Commit 65cdb388e4f493ad2ac005a9ed827be0049fd613

Authored by Victor Costa
1 parent d94cfe72

Fix tests

lib/ext/environment.rb
... ... @@ -6,7 +6,7 @@ class Environment
6 6 has_many :gamification_plugin_organization_badges, :through => :organizations
7 7  
8 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 10 end
11 11  
12 12 end
... ...
lib/gamification_plugin/api.rb
... ... @@ -3,7 +3,7 @@ class GamificationPlugin::API < Grape::API
3 3 resource :gamification_plugin do
4 4  
5 5 get 'badges' do
6   - environment.gamification_plugin_badges.group(:name).count
  6 + environment.gamification_plugin_badges.group('gamification_plugin_badges.name').count
7 7 end
8 8  
9 9 resource :my do
... ... @@ -75,4 +75,3 @@ class GamificationPlugin::API < Grape::API
75 75 end
76 76 end
77 77 end
78   -
... ...
test/functional/gamification_plugin_profile_controller_test.rb
... ... @@ -34,7 +34,7 @@ class GamificationPluginProfileControllerTest < ActionController::TestCase
34 34 person.add_badge(badge1.id)
35 35 person.add_badge(badge2.id)
36 36 get :dashboard, :profile => person.identifier
37   - assert_select '.badges .badge-list .badge', 1
  37 + assert_select '.badges .badge-list li.badge', 1
38 38 end
39 39  
40 40 end
... ...
test/unit/badge_rules_test.rb
... ... @@ -11,21 +11,21 @@ class BadgeRulesTest < ActiveSupport::TestCase
11 11 should "define badge rules for environment's badges" do
12 12 badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author)
13 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 15 end
16 16  
17 17 should "define badge rules for organization's badges" do
18 18 organization = fast_create(Organization)
19 19 badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author)
20 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 22 end
23 23  
24 24 should 'check organization returns true when badge belongs to the environment' do
25 25 badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author)
26 26 badge_rules = Merit::BadgeRules.new(environment)
27 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 29 end
30 30  
31 31 should 'check organization returns true when the comment belongs to the organization' do
... ... @@ -34,7 +34,7 @@ class BadgeRulesTest < ActiveSupport::TestCase
34 34 badge_rules = Merit::BadgeRules.new(environment)
35 35 article = fast_create(Article,:profile_id => organization.id)
36 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 38 end
39 39  
40 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 42 badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author)
43 43 badge_rules = Merit::BadgeRules.new(environment)
44 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 46 end
47 47  
48 48 end
... ...