Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/models/merit/badge_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ def initialize
grant_on 'comments#create', badge: 'commentator', level: 10 do |comment|
comment.author.comments.count == 10
end

grant_on 'search#index', badge: 'detective', level: 1

grant_on 'events#update', badge: 'host', level: 3

grant_on 'events#update', badge: 'great-host', level: 30

grant_on 'events#join', badge: 'participant', level: 2

grant_on 'events#join', badge: 'party-checker', level: 40

# If it has 5 votes, grant relevant-commenter badge
# grant_on 'comments#vote', badge: 'relevant-commenter',
Expand Down
1 change: 1 addition & 0 deletions app/models/merit/point_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize
score 5, on: ['blog_posts#create', 'pages#create'], category: 'information'
score 5, on: 'posts#create', category: 'communication'
score 2, on: 'comments#create', category: 'communication'
score 1, on: ['events#join', 'events#update'], category: 'social-activity'
end
end
end
31 changes: 30 additions & 1 deletion config/initializers/merit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,36 @@
name: 'damsel-in-distress',
description: 'only a true hero is honest enough to ask for help: create a support-request with the help button',
custom_fields: { difficulty: :silver }

}, {
id: (badge_id = badge_id+1),
name: 'detective',
description: 'Seek, and ye shall find: search something with the search button',
level: 1,
custom_fields: { difficulty: :bronce }
}, {
id: (badge_id = badge_id+1),
name: 'host',
description: 'creates 3 events',
level: 3,
custom_fields: { difficulty: :bronce }
}, {
id: (badge_id = badge_id+1),
name: 'great-host',
description: 'creates 30 events',
level: 30,
custom_fields: { difficulty: :silver }
}, {
id: (badge_id = badge_id+1),
name: 'participant',
description: 'creates 2 events',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mit dieser Beschreibung stimmt auch etwas nicht. Ein Teilnehmer erstellt doch nicht de Veranstaltung.

Sieh den Pull-Request lieber nochmal durch. Hierzu eignet sich diese Übersicht-Seite recht gut: https://github.com/fiedl/your_platform/pull/8/files

level: 2,
custom_fields: { difficulty: :bronce }
}, {
id: (badge_id = badge_id+1),
name: 'party-checker',
description: 'creates 40 events',
level: 40,
custom_fields: { difficulty: :silver }

}].each do |attrs|
Merit::Badge.create! attrs
Expand Down
37 changes: 37 additions & 0 deletions spec/features/merit_point_rules_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

feature "Merit Point Rules" do
include SessionSteps

background do
@user = create :user_with_account
end

scenario "joining event earns 1 point" do
# setting up scenario
@points = @user.points
@group = create(:group)
@group.assign_user @user, at: 1.year.ago
@event1 = @group.child_events.create name: "Gamification Hacking Workshop", start_at: 1.day.from_now
@event2 = @group.child_events.create name: "Another meeting", start_at: 10.day.from_now

# Just looking at events#index does nothing.
login @user
visit root_path
@user.reload.points.should == @points

# Joining an event should add a point.
visit root_path
within('.box.upcoming_events') { click_on @event1.name }
page.should have_selector '#join_event', visible: true
find('#join_event').click
@user.reload.points.should == @points+1

visit root_path
within('.box.upcoming_events') { click_on @event2.name }
page.should have_selector '#join_event', visible: true
find('#join_event').click
@user.reload.points.should == @points+2
end

end
44 changes: 44 additions & 0 deletions spec/models/merit/point_rules_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
require 'spec_helper'

describe User do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Datei point_rules_spec.rb lässt vermuten, dass hier Regeln beschrieben werden, nicht der User.

Ich würde vorschlagen, dass Du den Test als Feature-Spec konzipierst, ähnlich https://github.com/fiedl/your_platform/blob/master/spec/features/merit_badge_rules_spec.rb.


before do
@user = create( :user )
@user.save
@points = @user.points
end

subject { @user }

# Validation
# ==========================================================================================

it { should be_valid }


# Basic Properties
# ==========================================================================================

describe "events#join" do
subject { @user }
[ :first_name, :last_name, :alias, :email, :create_account, :female, :add_to_group ].each do |attr|
it { should respond_to( attr ) }
it { should respond_to( "#{attr}=".to_sym ) }
end
end

describe "events#join" do
subject { @user.join(@event); time_travel(2.seconds) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funktioniert das denn? Ich dachte, merit hängt sich an den Controller. Werden also für Veränderungen auf Model-Ebene (@user.join(...)) tatsächlich Punkte vergeben?

Ist dieser Test bei Dir grün?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja, auch auf travis. weil die Point-Rules am Modell vergeben werden. Ich schau ja nur, ob es mehr Punkte geworden sind.

describe "(joining an event)" do
before { @event = create(:event); subject }
specify { @event.attendees.should include @user}
specify { @event.attendees_group.members.should include @user }
specify "the user should have earned points" do
@user.points > @points
end
end

end

end