diff --git a/app/models/merit/badge_rules.rb b/app/models/merit/badge_rules.rb index 691d50269..003d7d77d 100644 --- a/app/models/merit/badge_rules.rb +++ b/app/models/merit/badge_rules.rb @@ -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', diff --git a/app/models/merit/point_rules.rb b/app/models/merit/point_rules.rb index eaab3fa2f..2b0cfa9a8 100644 --- a/app/models/merit/point_rules.rb +++ b/app/models/merit/point_rules.rb @@ -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 diff --git a/config/initializers/merit.rb b/config/initializers/merit.rb index f42d6799e..1e8b0fc8c 100644 --- a/config/initializers/merit.rb +++ b/config/initializers/merit.rb @@ -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', + 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 diff --git a/spec/features/merit_point_rules_spec.rb b/spec/features/merit_point_rules_spec.rb new file mode 100644 index 000000000..f223c05e9 --- /dev/null +++ b/spec/features/merit_point_rules_spec.rb @@ -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 diff --git a/spec/models/merit/point_rules_spec.rb b/spec/models/merit/point_rules_spec.rb new file mode 100644 index 000000000..ea1cd59e9 --- /dev/null +++ b/spec/models/merit/point_rules_spec.rb @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +require 'spec_helper' + +describe User do + + 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) } + 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