Commit 65cdb388e4f493ad2ac005a9ed827be0049fd613

Authored by Victor Costa
1 parent d94cfe72

Fix tests

lib/ext/environment.rb
@@ -6,7 +6,7 @@ class Environment @@ -6,7 +6,7 @@ class Environment
6 has_many :gamification_plugin_organization_badges, :through => :organizations 6 has_many :gamification_plugin_organization_badges, :through => :organizations
7 7
8 def gamification_plugin_badges 8 def gamification_plugin_badges
9 - GamificationPlugin::Badge.joins('inner join profiles on profiles.id = owner_id').where(['owner_id = ? or profiles.environment_id = ?', self.id, self.id]) 9 + GamificationPlugin::Badge.joins('left join profiles on profiles.id = owner_id').where(['owner_id = ? or profiles.environment_id = ?', self.id, self.id])
10 end 10 end
11 11
12 end 12 end
lib/gamification_plugin/api.rb
@@ -3,7 +3,7 @@ class GamificationPlugin::API < Grape::API @@ -3,7 +3,7 @@ class GamificationPlugin::API < Grape::API
3 resource :gamification_plugin do 3 resource :gamification_plugin do
4 4
5 get 'badges' do 5 get 'badges' do
6 - environment.gamification_plugin_badges.group(:name).count 6 + environment.gamification_plugin_badges.group('gamification_plugin_badges.name').count
7 end 7 end
8 8
9 resource :my do 9 resource :my do
@@ -75,4 +75,3 @@ class GamificationPlugin::API < Grape::API @@ -75,4 +75,3 @@ class GamificationPlugin::API < Grape::API
75 end 75 end
76 end 76 end
77 end 77 end
78 -  
test/functional/gamification_plugin_profile_controller_test.rb
@@ -34,7 +34,7 @@ class GamificationPluginProfileControllerTest < ActionController::TestCase @@ -34,7 +34,7 @@ class GamificationPluginProfileControllerTest < ActionController::TestCase
34 person.add_badge(badge1.id) 34 person.add_badge(badge1.id)
35 person.add_badge(badge2.id) 35 person.add_badge(badge2.id)
36 get :dashboard, :profile => person.identifier 36 get :dashboard, :profile => person.identifier
37 - assert_select '.badges .badge-list .badge', 1 37 + assert_select '.badges .badge-list li.badge', 1
38 end 38 end
39 39
40 end 40 end
test/unit/badge_rules_test.rb
@@ -11,21 +11,21 @@ class BadgeRulesTest < ActiveSupport::TestCase @@ -11,21 +11,21 @@ class BadgeRulesTest < ActiveSupport::TestCase
11 should "define badge rules for environment's badges" do 11 should "define badge rules for environment's badges" do
12 badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author) 12 badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author)
13 badge_rules = Merit::BadgeRules.new(environment) 13 badge_rules = Merit::BadgeRules.new(environment)
14 - assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name].first[:action]], badge_rules.defined_rules.keys 14 + assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first[:action]], badge_rules.defined_rules.keys
15 end 15 end
16 16
17 should "define badge rules for organization's badges" do 17 should "define badge rules for organization's badges" do
18 organization = fast_create(Organization) 18 organization = fast_create(Organization)
19 badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author) 19 badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author)
20 badge_rules = Merit::BadgeRules.new(environment) 20 badge_rules = Merit::BadgeRules.new(environment)
21 - assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name].first[:action]], badge_rules.defined_rules.keys 21 + assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first[:action]], badge_rules.defined_rules.keys
22 end 22 end
23 23
24 should 'check organization returns true when badge belongs to the environment' do 24 should 'check organization returns true when badge belongs to the environment' do
25 badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author) 25 badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author)
26 badge_rules = Merit::BadgeRules.new(environment) 26 badge_rules = Merit::BadgeRules.new(environment)
27 comment = fast_create(Comment) 27 comment = fast_create(Comment)
28 - assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name].first) 28 + assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first)
29 end 29 end
30 30
31 should 'check organization returns true when the comment belongs to the organization' do 31 should 'check organization returns true when the comment belongs to the organization' do
@@ -34,7 +34,7 @@ class BadgeRulesTest < ActiveSupport::TestCase @@ -34,7 +34,7 @@ class BadgeRulesTest < ActiveSupport::TestCase
34 badge_rules = Merit::BadgeRules.new(environment) 34 badge_rules = Merit::BadgeRules.new(environment)
35 article = fast_create(Article,:profile_id => organization.id) 35 article = fast_create(Article,:profile_id => organization.id)
36 comment = fast_create(Comment, :source_id => article.id) 36 comment = fast_create(Comment, :source_id => article.id)
37 - assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name].first) 37 + assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first)
38 end 38 end
39 39
40 should 'check organization returns false when the comment does not belongs to the organization' do 40 should 'check organization returns false when the comment does not belongs to the organization' do
@@ -42,7 +42,7 @@ class BadgeRulesTest < ActiveSupport::TestCase @@ -42,7 +42,7 @@ class BadgeRulesTest < ActiveSupport::TestCase
42 badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author) 42 badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author)
43 badge_rules = Merit::BadgeRules.new(environment) 43 badge_rules = Merit::BadgeRules.new(environment)
44 comment = fast_create(Comment) 44 comment = fast_create(Comment)
45 - assert !badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name].first) 45 + assert !badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first)
46 end 46 end
47 47
48 end 48 end