badge_rules_test.rb
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require_relative "../test_helper"
class BadgeRulesTest < ActiveSupport::TestCase
def setup
@environment = Environment.default
end
attr_accessor :environment
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.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.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.to_sym].first)
end
should 'check organization returns true when the comment belongs to the organization' do
organization = fast_create(Organization)
badge = GamificationPlugin::Badge.create!(:owner => organization, :name => :comment_author)
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.to_sym].first)
end
should 'check organization returns false when the comment does not belongs to the organization' do
organization = fast_create(Organization)
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.to_sym].first)
end
end