From 65cdb388e4f493ad2ac005a9ed827be0049fd613 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 25 Jan 2016 10:22:54 -0300 Subject: [PATCH] Fix tests --- lib/ext/environment.rb | 2 +- lib/gamification_plugin/api.rb | 3 +-- test/functional/gamification_plugin_profile_controller_test.rb | 2 +- test/unit/badge_rules_test.rb | 10 +++++----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/ext/environment.rb b/lib/ext/environment.rb index 4953b37..db6e517 100644 --- a/lib/ext/environment.rb +++ b/lib/ext/environment.rb @@ -6,7 +6,7 @@ class Environment has_many :gamification_plugin_organization_badges, :through => :organizations def gamification_plugin_badges - GamificationPlugin::Badge.joins('inner join profiles on profiles.id = owner_id').where(['owner_id = ? or profiles.environment_id = ?', self.id, self.id]) + GamificationPlugin::Badge.joins('left join profiles on profiles.id = owner_id').where(['owner_id = ? or profiles.environment_id = ?', self.id, self.id]) end end diff --git a/lib/gamification_plugin/api.rb b/lib/gamification_plugin/api.rb index 525826e..39305f4 100644 --- a/lib/gamification_plugin/api.rb +++ b/lib/gamification_plugin/api.rb @@ -3,7 +3,7 @@ class GamificationPlugin::API < Grape::API resource :gamification_plugin do get 'badges' do - environment.gamification_plugin_badges.group(:name).count + environment.gamification_plugin_badges.group('gamification_plugin_badges.name').count end resource :my do @@ -75,4 +75,3 @@ class GamificationPlugin::API < Grape::API end end end - diff --git a/test/functional/gamification_plugin_profile_controller_test.rb b/test/functional/gamification_plugin_profile_controller_test.rb index 4a47686..2f2f737 100644 --- a/test/functional/gamification_plugin_profile_controller_test.rb +++ b/test/functional/gamification_plugin_profile_controller_test.rb @@ -34,7 +34,7 @@ class GamificationPluginProfileControllerTest < ActionController::TestCase person.add_badge(badge1.id) person.add_badge(badge2.id) get :dashboard, :profile => person.identifier - assert_select '.badges .badge-list .badge', 1 + assert_select '.badges .badge-list li.badge', 1 end end diff --git a/test/unit/badge_rules_test.rb b/test/unit/badge_rules_test.rb index 93178f7..52fce1e 100644 --- a/test/unit/badge_rules_test.rb +++ b/test/unit/badge_rules_test.rb @@ -11,21 +11,21 @@ class BadgeRulesTest < ActiveSupport::TestCase should "define badge rules for environment's badges" do badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author) badge_rules = Merit::BadgeRules.new(environment) - assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name].first[:action]], badge_rules.defined_rules.keys + assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first[:action]], badge_rules.defined_rules.keys end should "define badge rules for organization's badges" do organization = fast_create(Organization) badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author) badge_rules = Merit::BadgeRules.new(environment) - assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name].first[:action]], badge_rules.defined_rules.keys + assert_equal [Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first[:action]], badge_rules.defined_rules.keys end should 'check organization returns true when badge belongs to the environment' do badge = GamificationPlugin::Badge.create!(:owner => environment, :name => :comment_author) badge_rules = Merit::BadgeRules.new(environment) comment = fast_create(Comment) - assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name].first) + assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first) end should 'check organization returns true when the comment belongs to the organization' do @@ -34,7 +34,7 @@ class BadgeRulesTest < ActiveSupport::TestCase badge_rules = Merit::BadgeRules.new(environment) article = fast_create(Article,:profile_id => organization.id) comment = fast_create(Comment, :source_id => article.id) - assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name].first) + assert badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first) end should 'check organization returns false when the comment does not belongs to the organization' do @@ -42,7 +42,7 @@ class BadgeRulesTest < ActiveSupport::TestCase badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author) badge_rules = Merit::BadgeRules.new(environment) comment = fast_create(Comment) - assert !badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name].first) + assert !badge_rules.check_organization_badge(badge, comment, Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first) end end -- libgit2 0.21.2