merit 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,8 @@
2
2
 
3
3
  ![Merit](http://i567.photobucket.com/albums/ss118/DeuceBigglebags/th_nspot26_300.jpg)
4
4
 
5
+ [![Build Status](https://secure.travis-ci.org/tute/merit.png?branch=master)](http://travis-ci.org/tute/merit)
6
+
5
7
 
6
8
  # Installation
7
9
 
@@ -124,33 +126,20 @@ installation, and configuring <tt>config.orm = :mongo_mapper</tt> in
124
126
 
125
127
  ---
126
128
 
127
- # Upgrade to 0.3.0
129
+ # Notes on upgrades
130
+
131
+ ## to 0.3.0
128
132
 
129
133
  Badges data is now stored in <tt>config/initializers/merit.rb</tt> using
130
134
  <tt>ambry</tt> syntax (not in the DB anymore, as that table needed to be in
131
135
  sync in all development environments).
132
136
 
133
- # Upgrade to 0.2.0
137
+ ## to 0.2.0
134
138
 
135
139
  Added <tt>had_errors</tt> boolean attribute to <tt>merit_actions</tt> table.
136
140
 
137
141
  ---
138
142
 
139
- # Test application
140
-
141
- To run tests follow:
142
-
143
- cd test/dummy
144
- rails g merit:install # Next n's for not overriding already defined rules
145
- n
146
- n
147
- n
148
- rails g merit user
149
- rake db:migrate ; rake db:seed
150
- cd ../.. ; rake test
151
-
152
- ---
153
-
154
143
  # To-do list
155
144
 
156
145
  * Use ActiveSupport's Array#wrap where I build arrays by hand
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  require 'rake'
10
- require 'rake/rdoctask'
10
+ require 'rdoc/task'
11
11
 
12
12
  require 'rake/testtask'
13
13
 
@@ -15,7 +15,7 @@ module Merit
15
15
 
16
16
  def badges
17
17
  create_sash_if_none
18
- Badge.find_by_id(sash.badge_ids).to_a
18
+ Badge.find_by_id(sash.badge_ids)
19
19
  end
20
20
 
21
21
  # Create sash if doesn't have
@@ -1,7 +1,10 @@
1
1
  class BadgesSash < ActiveRecord::Base
2
- belongs_to :badge
3
2
  belongs_to :sash
4
3
 
4
+ def badge
5
+ Badge.find(badge_id)
6
+ end
7
+
5
8
  # To be used in the application, mark badge granting as notified to user
6
9
  def set_notified!(badge, sash)
7
10
  # With composite keys ARel complained, had to use SQL
@@ -1,9 +1,12 @@
1
1
  class Sash < ActiveRecord::Base
2
2
  has_many :badges_sashes
3
- has_many :badges, :through => :badges_sashes
3
+
4
+ def badge_ids
5
+ badges_sashes.collect(&:badge_id)
6
+ end
4
7
 
5
8
  def add_badge(badge_id)
6
- BadgesSash.create(sash: self, badge_id: badge_id)
9
+ BadgesSash.create(sash_id: self.id, badge_id: badge_id)
7
10
  end
8
11
  def rm_badge(badge_id)
9
12
  ActiveRecord::Base.connection.execute("DELETE FROM badges_sashes
@@ -32,7 +32,7 @@ module Merit
32
32
  defined_rules.each do |scoped_model, rankings| # For each model
33
33
  rankings.each do |ranking, rules| # For each model's ranking (stars, etc)
34
34
  rules.each do |rule| # For each ranking's rule (level)
35
- scoped_model.all.each {|obj| grant_rank(rule, obj) }
35
+ scoped_model.all.each{|obj| grant_rank(rule, obj) }
36
36
  end
37
37
  end
38
38
  end
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.summary = "General reputation Rails engine."
6
6
  s.description = "General reputation Rails engine."
7
7
  s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
  s.authors = ["Tute Costa"]
10
10
  s.email = 'tutecosta@gmail.com'
11
11
  s.add_dependency 'ambry'
@@ -0,0 +1,8 @@
1
+ # Use this hook to configure merit parameters
2
+ Merit.setup do |config|
3
+ # Check rules on each request or in background
4
+ # config.checks_on_each_request = true
5
+
6
+ # Define ORM. Could be :active_record (default) and :mongo_mapper
7
+ # config.orm = :active_record
8
+ end
@@ -0,0 +1,18 @@
1
+ class CreateMeritActions < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :merit_actions do |t|
4
+ t.integer :user_id # source
5
+ t.string :action_method
6
+ t.integer :action_value
7
+ t.boolean :had_errors
8
+ t.string :target_model
9
+ t.integer :target_id
10
+ t.boolean :processed, :default => false
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :merit_actions
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSashes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :sashes do |t|
4
+ t.timestamps
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :sashes
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ class CreateBadgesSashes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :badges_sashes, :id => false do |t|
4
+ t.integer :badge_id, :sash_id
5
+ t.boolean :notified_user, :default => false
6
+ t.datetime :created_at
7
+ end
8
+ add_index :badges_sashes, [:badge_id, :sash_id]
9
+ add_index :badges_sashes, :badge_id
10
+ add_index :badges_sashes, :sash_id
11
+ end
12
+
13
+ def self.down
14
+ drop_table :badges_sashes
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ class AddFieldsToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :sash_id, :integer
4
+ add_column :users, :points, :integer, :default => 0
5
+ User.all.each{|user| user.update_attribute(:points, 0) } # Update existing entries
6
+ end
7
+
8
+ def self.down
9
+ remove_column :users, :sash_id
10
+ remove_column :users, :points
11
+ end
12
+ end
@@ -28,7 +28,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
28
28
  click_button('Create Comment')
29
29
 
30
30
  user = User.where(:name => 'test-user').first
31
- assert_equal [Badge.by_name('commenter').by_level(10).first], user.badges
31
+ assert_equal [Badge.by_name('commenter').by_level(10).first], user.badges.to_a
32
32
 
33
33
  # Vote (to 5) a user's comment, assert relevant-commenter badge granted
34
34
  relevant_comment = user.comments.where(:votes => 8).first
@@ -38,13 +38,13 @@ class NavigationTest < ActiveSupport::IntegrationCase
38
38
  end
39
39
 
40
40
  relevant_badge = Badge.by_name('relevant-commenter').first
41
- user_badges = User.where(:name => 'test-user').first.badges
41
+ user_badges = User.where(:name => 'test-user').first.badges.to_a
42
42
  assert user_badges.include?(relevant_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain relevant-commenter badge."
43
43
 
44
44
  # Edit user's name by long name
45
45
  # tests ruby code in grant_on is being executed, and gives badge
46
46
  user = User.where(:name => 'test-user').first
47
- user_badges = user.badges
47
+ user_badges = user.badges.to_a
48
48
 
49
49
  visit "/users/#{user.id}/edit"
50
50
  fill_in 'Name', :with => 'long_name!'
@@ -52,7 +52,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
52
52
 
53
53
  user = User.where(:name => 'long_name!').first
54
54
  autobiographer_badge = Badge.by_name('autobiographer').first
55
- assert user.badges.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain autobiographer badge."
55
+ assert user.badges.to_a.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain autobiographer badge."
56
56
 
57
57
  # Edit user's name by short name
58
58
  # tests ruby code in grant_on is being executed, and removes badge
@@ -61,7 +61,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
61
61
  click_button('Update User')
62
62
 
63
63
  user = User.where(:name => 'abc').first
64
- assert !user.badges.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should remove autobiographer badge."
64
+ assert !user.badges.to_a.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should remove autobiographer badge."
65
65
  end
66
66
 
67
67
  test 'user workflow should add up points at some times' do
@@ -107,7 +107,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
107
107
  user = User.where(:name => 'ab').first
108
108
  stars2 = Badge.by_name(:stars).by_level(2).first
109
109
  MeritRankRules.new.check_rank_rules
110
- assert_equal user.badges, [stars2], "User badges: #{user.badges.collect(&:name).inspect} should contain only 2-stars badge."
110
+ assert_equal user.badges.to_a, [stars2], "User badges: #{user.badges.collect(&:name).inspect} should contain only 2-stars badge."
111
111
 
112
112
  # Edit user's name by short name. Doesn't go back to previous rank.
113
113
  visit "/users/#{user.id}/edit"
@@ -116,7 +116,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
116
116
 
117
117
  user = User.where(:name => 'a').first
118
118
  MeritRankRules.new.check_rank_rules
119
- assert_equal user.badges, [stars2], "User badges: #{user.badges.collect(&:name).inspect} should contain only 2-stars badge."
119
+ assert_equal user.badges.to_a, [stars2], "User badges: #{user.badges.collect(&:name).inspect} should contain only 2-stars badge."
120
120
 
121
121
  # Edit user's name by 5 chars name
122
122
  visit "/users/#{user.id}/edit"
@@ -127,6 +127,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
127
127
  stars5 = Badge.by_name(:stars).by_level(5).first
128
128
  assert_equal Badge.find_by_id(user.sash.badge_ids).by_name(:stars).count, 1, "Should not contain more than 2 stars ranking."
129
129
  MeritRankRules.new.check_rank_rules
130
- assert user.badges.include?(stars5), "User badges: #{user.badges.collect(&:name).inspect} should contain 5-stars badge."
130
+ user.reload
131
+ assert user.badges.to_a.include?(stars5), "User badges: #{user.badges.collect(&:inspect)} should contain 5-stars badge."
131
132
  end
132
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-16 00:00:00.000000000 Z
12
+ date: 2012-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ambry
16
- requirement: &70301339044400 !ruby/object:Gem::Requirement
16
+ requirement: &70196766610980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70301339044400
24
+ version_requirements: *70196766610980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70301339043920 !ruby/object:Gem::Requirement
27
+ requirement: &70196766610400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70301339043920
35
+ version_requirements: *70196766610400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70301339043500 !ruby/object:Gem::Requirement
38
+ requirement: &70196766609980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70301339043500
46
+ version_requirements: *70196766609980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: haml
49
- requirement: &70301339043080 !ruby/object:Gem::Requirement
49
+ requirement: &70196766609560 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70301339043080
57
+ version_requirements: *70196766609560
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: capybara
60
- requirement: &70301339042640 !ruby/object:Gem::Requirement
60
+ requirement: &70196766609100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70301339042640
68
+ version_requirements: *70196766609100
69
69
  description: General reputation Rails engine.
70
70
  email: tutecosta@gmail.com
71
71
  executables: []
@@ -139,6 +139,7 @@ files:
139
139
  - test/dummy/config/initializers/backtrace_silencers.rb
140
140
  - test/dummy/config/initializers/badges_data.rb
141
141
  - test/dummy/config/initializers/inflections.rb
142
+ - test/dummy/config/initializers/merit.rb
142
143
  - test/dummy/config/initializers/mime_types.rb
143
144
  - test/dummy/config/initializers/secret_token.rb
144
145
  - test/dummy/config/initializers/session_store.rb
@@ -146,6 +147,10 @@ files:
146
147
  - test/dummy/config/routes.rb
147
148
  - test/dummy/db/migrate/20110421191249_create_users.rb
148
149
  - test/dummy/db/migrate/20110421191250_create_comments.rb
150
+ - test/dummy/db/migrate/20120318022217_create_merit_actions.rb
151
+ - test/dummy/db/migrate/20120318022218_create_sashes.rb
152
+ - test/dummy/db/migrate/20120318022219_create_badges_sashes.rb
153
+ - test/dummy/db/migrate/20120318022220_add_fields_to_users.rb
149
154
  - test/dummy/db/schema.rb
150
155
  - test/dummy/db/seeds.rb
151
156
  - test/dummy/public/404.html