mm-voteable 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,14 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem 'mongo', '1.1.2'
5
- gem 'bson_ext', '1.1.2'
6
- gem 'mongo_ext'
4
+ gem 'bson_ext'
7
5
  gem 'mongo_mapper'
8
6
  gem 'i18n'
9
7
 
10
- gem 'log_buddy'
11
-
12
8
  gem 'ruby-debug'
13
9
  gem "rspec", "~> 2.1.0"
14
10
  gem "yard", "~> 0.6.0"
@@ -1,24 +1,22 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.0.1)
5
- bson (1.1.2)
6
- bson_ext (1.1.2)
4
+ activesupport (3.0.4)
5
+ bson (1.2.4)
6
+ bson_ext (1.2.4)
7
7
  columnize (0.3.2)
8
8
  diff-lcs (1.1.2)
9
9
  git (1.2.5)
10
- i18n (0.4.2)
11
- jeweler (1.5.1)
10
+ i18n (0.5.0)
11
+ jeweler (1.5.2)
12
12
  bundler (~> 1.0.0)
13
13
  git (>= 1.2.5)
14
14
  rake
15
15
  jnunemaker-validatable (1.8.4)
16
16
  activesupport (>= 2.3.4)
17
17
  linecache (0.43)
18
- log_buddy (0.5.0)
19
- mongo (1.1.2)
20
- bson (>= 1.1.1)
21
- mongo_ext (0.19.3)
18
+ mongo (1.2.4)
19
+ bson (>= 1.2.4)
22
20
  mongo_mapper (0.8.6)
23
21
  activesupport (>= 2.3.4)
24
22
  jnunemaker-validatable (~> 1.8.4)
@@ -40,19 +38,16 @@ GEM
40
38
  ruby-debug-base (~> 0.10.4.0)
41
39
  ruby-debug-base (0.10.4)
42
40
  linecache (>= 0.3)
43
- yard (0.6.2)
41
+ yard (0.6.4)
44
42
 
45
43
  PLATFORMS
46
44
  ruby
47
45
 
48
46
  DEPENDENCIES
49
- bson_ext (= 1.1.2)
47
+ bson_ext
50
48
  bundler (~> 1.0.0)
51
49
  i18n
52
50
  jeweler (~> 1.5.1)
53
- log_buddy
54
- mongo (= 1.1.2)
55
- mongo_ext
56
51
  mongo_mapper
57
52
  rcov
58
53
  rspec (~> 2.1.0)
@@ -1,6 +1,6 @@
1
1
  = mm-voteable
2
2
 
3
- A very simple mongomapper plugin to add vote up/down functionality to your application.
3
+ A very simple mongomapper plugin to add vote up/down superpowers to your models.
4
4
 
5
5
 
6
6
  == Usage
@@ -20,12 +20,13 @@ Then add the voteable plugin to you MongoMapper::Document
20
20
  include MongoMapper::Document
21
21
  plugin MongoMapper::Plugins::Voteable
22
22
 
23
- def on_add_vote(comment)
24
- do something when a comment is added...
23
+ def on_add_vote(vote)
24
+ do something when a vote is added...
25
25
  end
26
26
  end
27
27
 
28
- You must implement the on_add_comment callback! - however it can be an empty implementation
28
+ You must implement the on_add_vote callback! -
29
+ It can be an empty implementation, but I use it to create ActivityStream Items after someone votes on a NewsArticle
29
30
 
30
31
  @post = Post.create
31
32
  @voter = User.create
@@ -37,9 +38,18 @@ You must implement the on_add_comment callback! - however it can be an empty imp
37
38
  @posts.votes #=> [<Vote>]
38
39
  @posts.voters #=> [<User>]
39
40
  @posts.voters.include?(@voter) #=> true
41
+
42
+
43
+ == Limitations
44
+
45
+ I made this plugin for voting up and down on articles (kind of like stack overflow) so there are currently some limitations
46
+
47
+ * the vote value can only be one of 1 or -1
48
+ * the voteable model has a 'user' belongs_to association
49
+ * a user can only vote once on a voteable item
50
+ * the owner of a voteable item, cannot vote
40
51
 
41
- == Assumptions
42
- * your voteable model has a 'user' association
52
+ Feel free to code any of these limitations out and send me a patch, this is just how I have used it so far
43
53
 
44
54
 
45
55
  == Contributing to mm-voteable
data/Rakefile CHANGED
@@ -15,8 +15,8 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "mm-voteable"
16
16
  gem.homepage = "http://github.com/icaruswings/mm-voteable"
17
17
  gem.license = "MIT"
18
- gem.summary = %Q{A very simple mongomapper plugin to add vote up/down functionality to your application}
19
- gem.description = %Q{A very simple mongomapper plugin to add vote up/down functionality to your application}
18
+ gem.summary = %Q{A very simple mongomapper plugin to add vote up/down superpowers to your models}
19
+ gem.description = %Q{A very simple mongomapper plugin to add vote up/down superpowers to your models}
20
20
  gem.email = "luke@icaruswings.com"
21
21
  gem.authors = ["Luke Cunningham"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -4,14 +4,12 @@ class Vote
4
4
  key :voter_id, ObjectId, :required => true
5
5
  belongs_to :voter, :class_name => 'User'
6
6
 
7
- key :value, Integer, :required => true
7
+ key :value, Integer, :required => true, :in => [1,-1]
8
8
 
9
9
  key :voteable_id, ObjectId, :required => true
10
10
  key :voteable_type, String, :required => true
11
11
  belongs_to :voteable, :polymorphic => true
12
12
 
13
- validates_inclusion_of :value, :within => [1,-1]
14
-
15
13
  validate :should_be_unique
16
14
  validate :should_not_be_owner
17
15
 
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mm-voteable}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Luke Cunningham"]
12
- s.date = %q{2010-11-18}
13
- s.description = %q{A very simple mongomapper plugin to add vote up/down functionality to your application}
12
+ s.date = %q{2011-02-26}
13
+ s.description = %q{A very simple mongomapper plugin to add vote up/down superpowers to your models}
14
14
  s.email = %q{luke@icaruswings.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.licenses = ["MIT"]
38
38
  s.require_paths = ["lib"]
39
39
  s.rubygems_version = %q{1.3.7}
40
- s.summary = %q{A very simple mongomapper plugin to add vote up/down functionality to your application}
40
+ s.summary = %q{A very simple mongomapper plugin to add vote up/down superpowers to your models}
41
41
  s.test_files = [
42
42
  "spec/mm-voteable_spec.rb",
43
43
  "spec/spec_helper.rb",
@@ -49,12 +49,9 @@ Gem::Specification.new do |s|
49
49
  s.specification_version = 3
50
50
 
51
51
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_development_dependency(%q<mongo>, ["= 1.1.2"])
53
- s.add_development_dependency(%q<bson_ext>, ["= 1.1.2"])
54
- s.add_development_dependency(%q<mongo_ext>, [">= 0"])
52
+ s.add_development_dependency(%q<bson_ext>, [">= 0"])
55
53
  s.add_development_dependency(%q<mongo_mapper>, [">= 0"])
56
54
  s.add_development_dependency(%q<i18n>, [">= 0"])
57
- s.add_development_dependency(%q<log_buddy>, [">= 0"])
58
55
  s.add_development_dependency(%q<ruby-debug>, [">= 0"])
59
56
  s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
60
57
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
@@ -62,12 +59,9 @@ Gem::Specification.new do |s|
62
59
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
63
60
  s.add_development_dependency(%q<rcov>, [">= 0"])
64
61
  else
65
- s.add_dependency(%q<mongo>, ["= 1.1.2"])
66
- s.add_dependency(%q<bson_ext>, ["= 1.1.2"])
67
- s.add_dependency(%q<mongo_ext>, [">= 0"])
62
+ s.add_dependency(%q<bson_ext>, [">= 0"])
68
63
  s.add_dependency(%q<mongo_mapper>, [">= 0"])
69
64
  s.add_dependency(%q<i18n>, [">= 0"])
70
- s.add_dependency(%q<log_buddy>, [">= 0"])
71
65
  s.add_dependency(%q<ruby-debug>, [">= 0"])
72
66
  s.add_dependency(%q<rspec>, ["~> 2.1.0"])
73
67
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
@@ -76,12 +70,9 @@ Gem::Specification.new do |s|
76
70
  s.add_dependency(%q<rcov>, [">= 0"])
77
71
  end
78
72
  else
79
- s.add_dependency(%q<mongo>, ["= 1.1.2"])
80
- s.add_dependency(%q<bson_ext>, ["= 1.1.2"])
81
- s.add_dependency(%q<mongo_ext>, [">= 0"])
73
+ s.add_dependency(%q<bson_ext>, [">= 0"])
82
74
  s.add_dependency(%q<mongo_mapper>, [">= 0"])
83
75
  s.add_dependency(%q<i18n>, [">= 0"])
84
- s.add_dependency(%q<log_buddy>, [">= 0"])
85
76
  s.add_dependency(%q<ruby-debug>, [">= 0"])
86
77
  s.add_dependency(%q<rspec>, ["~> 2.1.0"])
87
78
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
@@ -17,14 +17,20 @@ describe "Vote" do
17
17
  @vote.should be_valid
18
18
  end
19
19
 
20
- it "should be valid if already voted" do
21
- voteable = VoteableWithCallback.create(:user_id => @user.id)
22
- vote = voteable.votes.build(:value => 1, :voter => @user)
20
+ it "should not be valid if already voted" do
21
+ @vote.save
22
+ vote = @voteable.votes.build(:value => 1, :voter => @user)
23
23
 
24
24
  vote.should_not be_valid
25
25
  end
26
26
 
27
- it "should be valid if voteable owner" do
27
+ it "should not be valid value is not one of 1 or -1" do
28
+ @vote.value = 3
29
+
30
+ @vote.should_not be_valid
31
+ end
32
+
33
+ it "should not be valid if voteable owner" do
28
34
  voteable = VoteableWithCallback.create(:user_id => @user.id)
29
35
  vote = voteable.votes.build(:value => 1, :voter => @user)
30
36
 
@@ -4,10 +4,6 @@ require 'bundler/setup'
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
 
7
- require 'fileutils'
8
- require 'ostruct'
9
- require 'log_buddy'
10
-
11
7
  require 'rspec'
12
8
 
13
9
  require 'mm-voteable'
@@ -16,25 +12,9 @@ require 'mm-voteable'
16
12
  # in ./support/ and its subdirectories.
17
13
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
18
14
 
19
- log_dir = File.expand_path('../../log', __FILE__)
20
- FileUtils.mkdir_p(log_dir) unless File.exist?(log_dir)
21
-
22
- logger = Logger.new(log_dir + '/test.log')
23
- LogBuddy.init(:logger => logger)
24
-
25
- MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => logger)
15
+ MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
26
16
  MongoMapper.database = "mm-test-#{RUBY_VERSION.gsub('.', '-')}"
27
17
  MongoMapper.database.collections.each { |c| c.drop_indexes }
28
18
 
29
-
30
19
  RSpec.configure do |config|
31
-
32
- config.after(:each) do
33
- MongoMapper.database.collections.collect do |collection|
34
- unless %w(system.js system.indexes system.users).any? { |name| name == collection.name }
35
- MongoMapper.database.drop_collection(collection.name)
36
- end
37
- end
38
- end
39
-
40
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-voteable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Cunningham
@@ -15,44 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-18 00:00:00 +11:00
18
+ date: 2011-02-26 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  prerelease: false
23
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - "="
27
- - !ruby/object:Gem::Version
28
- hash: 23
29
- segments:
30
- - 1
31
- - 1
32
- - 2
33
- version: 1.1.2
34
- name: mongo
35
- requirement: *id001
36
- type: :development
37
- - !ruby/object:Gem::Dependency
38
- prerelease: false
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - "="
43
- - !ruby/object:Gem::Version
44
- hash: 23
45
- segments:
46
- - 1
47
- - 1
48
- - 2
49
- version: 1.1.2
50
- name: bson_ext
51
- requirement: *id002
52
- type: :development
53
- - !ruby/object:Gem::Dependency
54
- prerelease: false
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
56
24
  none: false
57
25
  requirements:
58
26
  - - ">="
@@ -61,12 +29,12 @@ dependencies:
61
29
  segments:
62
30
  - 0
63
31
  version: "0"
64
- name: mongo_ext
65
- requirement: *id003
32
+ name: bson_ext
33
+ requirement: *id001
66
34
  type: :development
67
35
  - !ruby/object:Gem::Dependency
68
36
  prerelease: false
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
70
38
  none: false
71
39
  requirements:
72
40
  - - ">="
@@ -76,11 +44,11 @@ dependencies:
76
44
  - 0
77
45
  version: "0"
78
46
  name: mongo_mapper
79
- requirement: *id004
47
+ requirement: *id002
80
48
  type: :development
81
49
  - !ruby/object:Gem::Dependency
82
50
  prerelease: false
83
- version_requirements: &id005 !ruby/object:Gem::Requirement
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
84
52
  none: false
85
53
  requirements:
86
54
  - - ">="
@@ -90,25 +58,11 @@ dependencies:
90
58
  - 0
91
59
  version: "0"
92
60
  name: i18n
93
- requirement: *id005
94
- type: :development
95
- - !ruby/object:Gem::Dependency
96
- prerelease: false
97
- version_requirements: &id006 !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
106
- name: log_buddy
107
- requirement: *id006
61
+ requirement: *id003
108
62
  type: :development
109
63
  - !ruby/object:Gem::Dependency
110
64
  prerelease: false
111
- version_requirements: &id007 !ruby/object:Gem::Requirement
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
112
66
  none: false
113
67
  requirements:
114
68
  - - ">="
@@ -118,11 +72,11 @@ dependencies:
118
72
  - 0
119
73
  version: "0"
120
74
  name: ruby-debug
121
- requirement: *id007
75
+ requirement: *id004
122
76
  type: :development
123
77
  - !ruby/object:Gem::Dependency
124
78
  prerelease: false
125
- version_requirements: &id008 !ruby/object:Gem::Requirement
79
+ version_requirements: &id005 !ruby/object:Gem::Requirement
126
80
  none: false
127
81
  requirements:
128
82
  - - ~>
@@ -134,11 +88,11 @@ dependencies:
134
88
  - 0
135
89
  version: 2.1.0
136
90
  name: rspec
137
- requirement: *id008
91
+ requirement: *id005
138
92
  type: :development
139
93
  - !ruby/object:Gem::Dependency
140
94
  prerelease: false
141
- version_requirements: &id009 !ruby/object:Gem::Requirement
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
142
96
  none: false
143
97
  requirements:
144
98
  - - ~>
@@ -150,11 +104,11 @@ dependencies:
150
104
  - 0
151
105
  version: 0.6.0
152
106
  name: yard
153
- requirement: *id009
107
+ requirement: *id006
154
108
  type: :development
155
109
  - !ruby/object:Gem::Dependency
156
110
  prerelease: false
157
- version_requirements: &id010 !ruby/object:Gem::Requirement
111
+ version_requirements: &id007 !ruby/object:Gem::Requirement
158
112
  none: false
159
113
  requirements:
160
114
  - - ~>
@@ -166,11 +120,11 @@ dependencies:
166
120
  - 0
167
121
  version: 1.0.0
168
122
  name: bundler
169
- requirement: *id010
123
+ requirement: *id007
170
124
  type: :development
171
125
  - !ruby/object:Gem::Dependency
172
126
  prerelease: false
173
- version_requirements: &id011 !ruby/object:Gem::Requirement
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
174
128
  none: false
175
129
  requirements:
176
130
  - - ~>
@@ -182,11 +136,11 @@ dependencies:
182
136
  - 1
183
137
  version: 1.5.1
184
138
  name: jeweler
185
- requirement: *id011
139
+ requirement: *id008
186
140
  type: :development
187
141
  - !ruby/object:Gem::Dependency
188
142
  prerelease: false
189
- version_requirements: &id012 !ruby/object:Gem::Requirement
143
+ version_requirements: &id009 !ruby/object:Gem::Requirement
190
144
  none: false
191
145
  requirements:
192
146
  - - ">="
@@ -196,9 +150,9 @@ dependencies:
196
150
  - 0
197
151
  version: "0"
198
152
  name: rcov
199
- requirement: *id012
153
+ requirement: *id009
200
154
  type: :development
201
- description: A very simple mongomapper plugin to add vote up/down functionality to your application
155
+ description: A very simple mongomapper plugin to add vote up/down superpowers to your models
202
156
  email: luke@icaruswings.com
203
157
  executables: []
204
158
 
@@ -256,7 +210,7 @@ rubyforge_project:
256
210
  rubygems_version: 1.3.7
257
211
  signing_key:
258
212
  specification_version: 3
259
- summary: A very simple mongomapper plugin to add vote up/down functionality to your application
213
+ summary: A very simple mongomapper plugin to add vote up/down superpowers to your models
260
214
  test_files:
261
215
  - spec/mm-voteable_spec.rb
262
216
  - spec/spec_helper.rb