diff --git a/lib/ext/article.rb b/lib/ext/article.rb deleted file mode 100644 index 4536c61..0000000 --- a/lib/ext/article.rb +++ /dev/null @@ -1,8 +0,0 @@ -require_dependency 'article' - -class Article - - has_merit - has_merit_actions - -end diff --git a/lib/ext/text_article.rb b/lib/ext/text_article.rb new file mode 100644 index 0000000..ec3c73a --- /dev/null +++ b/lib/ext/text_article.rb @@ -0,0 +1,8 @@ +require_dependency 'text_article' + +class TextArticle + + has_merit + has_merit_actions + +end diff --git a/script/process_merit_rules.rb b/script/process_merit_rules.rb index 3492afa..fc153f5 100644 --- a/script/process_merit_rules.rb +++ b/script/process_merit_rules.rb @@ -7,14 +7,14 @@ def create_action(obj, index, count) end end -puts "Destroy all merit actions" -Merit::Action.destroy_all +#puts "Destroy all merit actions" +#Merit::Action.destroy_all -count = Person.count -Person.all.each.with_index(1) do |person, i| - puts "#{i}/#{count} Remove sash from #{person.identifier}" - person.sash.destroy unless person.sash.nil? -end +#count = Person.count +#Person.all.each.with_index(1) do |person, i| +# puts "#{i}/#{count} Remove sash from #{person.identifier}" +# person.sash.destroy unless person.sash.nil? +#end Environment.all.each do |environment| @@ -23,9 +23,9 @@ Environment.all.each do |environment| Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) - article_count = environment.articles.count + article_count = environment.articles.text_articles.count article_index = 0 - environment.articles.find_each do |article| + environment.articles.text_articles.find_each do |article| article_index += 1 create_action(article, article_index, article_count) diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 5612c6f..a33c587 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -11,12 +11,12 @@ class ArticleTest < ActiveSupport::TestCase attr_accessor :person, :environment should 'add merit points to author when create a new article' do - create(Article, :profile_id => person.id, :author => person) + create(TextArticle, :profile_id => person.id, :author => person) assert_equal 1, person.score_points.count end should 'subtract merit points to author when destroy an article' do - article = create(Article, :profile_id => person.id, :author => person) + article = create(TextArticle, :profile_id => person.id, :author => person) assert_equal 1, person.score_points.count article.destroy assert_equal 2, person.score_points.count @@ -27,7 +27,7 @@ class ArticleTest < ActiveSupport::TestCase GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1) GamificationPlugin.gamification_set_rules(environment) - 5.times { create(Article, :profile_id => person.id, :author => person) } + 5.times { create(TextArticle, :profile_id => person.id, :author => person) } assert_equal 'article_author', person.badges.first.name assert_equal 1, person.badges.first.level end @@ -37,13 +37,13 @@ class ArticleTest < ActiveSupport::TestCase GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10}) GamificationPlugin.gamification_set_rules(environment) - 10.times { create(Article, :profile_id => person.id, :author => person) } + 10.times { create(TextArticle, :profile_id => person.id, :author => person) } assert_equal ['article_author'], person.badges.map(&:name).uniq assert_equal [1, 2], person.badges.map(&:level) end should 'add merit points to article owner when an user like it' do - article = create(Article, :name => 'Test', :profile => person, :author => person) + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) assert_difference 'article.author.points(:category => :vote_voteable_author)', 50 do Vote.create!(:voter => person, :voteable => article, :vote => 1) @@ -51,7 +51,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'add merit points to article when an user like it' do - article = create(Article, :name => 'Test', :profile => person, :author => person) + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) article = article.reload assert_difference 'article.points(:category => :vote_voteable)', 50 do @@ -62,12 +62,12 @@ class ArticleTest < ActiveSupport::TestCase should 'add merit points to community when create a new article' do community = fast_create(Community) assert_difference 'community.score_points.count' do - create(Article, :profile_id => community.id, :author => person) + create(TextArticle, :profile_id => community.id, :author => person) end end should 'add merit points to voter when he likes an article' do - article = create(Article, :name => 'Test', :profile => person, :author => person) + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) assert_difference 'article.author.points(:category => :vote_voter)', 10 do Vote.create!(:voter => person, :voteable => article, :vote => 1) @@ -75,7 +75,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'add merit points to voter when he dislikes an article' do - article = create(Article, :name => 'Test', :profile => person, :author => person) + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) assert_difference 'article.author.points(:category => :vote_voter)', 10 do Vote.create!(:voter => person, :voteable => article, :vote => -1) @@ -86,7 +86,7 @@ class ArticleTest < ActiveSupport::TestCase GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received') GamificationPlugin.gamification_set_rules(environment) - article = create(Article, :name => 'Test', :profile => person, :author => person) + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) } Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) assert_equal [], person.badges @@ -98,7 +98,7 @@ class ArticleTest < ActiveSupport::TestCase GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received') GamificationPlugin.gamification_set_rules(environment) - article = create(Article, :name => 'Test', :profile => person, :author => person) + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) } Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) assert_equal [], person.badges diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index c9ec528..dc80bda 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -35,7 +35,7 @@ class ProfileTest < ActiveSupport::TestCase GamificationPlugin.gamification_set_rules(environment) person = create_user('testuser').person assert_equal 0, person.level - create(Article, :profile_id => profile.id, :author => person) + create(TextArticle, :profile_id => profile.id, :author => person) assert_equal 3, person.reload.level end -- libgit2 0.21.2