ibham 0.1.1.rc1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -5,3 +5,7 @@
5
5
  ## V0.1.1.rc1
6
6
 
7
7
  * Save the vote when calling cast_vote method
8
+
9
+ ## V0.1.1
10
+
11
+ * Better desription for the gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Ibham [![Build Status](https://secure.travis-ci.org/bloc40/ibham.png)](http://travis-ci.org/bloc40/ibham)
1
+ # Ibham [![Build Status](https://secure.travis-ci.org/bloc40/ibham.png)](http://travis-ci.org/bloc40/ibham) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/bloc40/ibham)
2
2
 
3
- TODO: Write a gem description
3
+ Ibham is a gem that allows Rails apps to compute and display voting scores for active records models.
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,9 +16,59 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install ibham
18
18
 
19
- ## Usage
19
+ Generate the migration
20
20
 
21
- TODO: Write usage instructions here
21
+ $ rails g ibham:install
22
+ $ rake db:migrate
23
+
24
+ # Usage
25
+
26
+ Let's say you have a user model (the voter). You need to add the mixin
27
+ *acts_as_voter* to that model:
28
+
29
+ class User < ActiveRecord::Base
30
+ acts_as_voter
31
+ end
32
+
33
+ And let's say you have an item model that the user can cast vote for
34
+ (the voteable). you need to add the mixin *acts_as_voteable* to the item
35
+ model:
36
+
37
+ class Item < ActiveRecord::Base
38
+ acts_as_voteable
39
+ end
40
+
41
+ ### Casting votes
42
+
43
+ The user can cast votes in the following ways:
44
+
45
+ # Let's first create a user and an item:
46
+ user = User.create
47
+ item = Item.create
48
+
49
+ user.vote_up(item) # Adds a positive vote
50
+ user.vote_down(item) # Adds a negative vote
51
+
52
+ or
53
+
54
+ # The only allowed values are 1 and -1
55
+ user.cast_vote(item, 1) # Adds a positive vote
56
+ user.cast_vote(item, -1) # Adds a negative vote
57
+
58
+ Since a user can cast only one vote per item, to check if the user can
59
+ cast vote for an item:
60
+
61
+ user.can_vote_for?(item)
62
+
63
+ ### Retrieving votes
64
+
65
+ To retrieve the votes:
66
+
67
+ item.up_votes # Return the total number of positive votes
68
+ item.down_votes # Return the total number of negative votes
69
+
70
+ item.up_percentage # Return the percentage of positive votes
71
+ item.down_percentage # Return the percentage of negative votes
22
72
 
23
73
  ## Contributing
24
74
 
data/lib/ibham/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ibham
2
- VERSION = '0.1.1.rc1'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/models/vote.rb CHANGED
@@ -5,5 +5,5 @@ class Vote < ActiveRecord::Base
5
5
  belongs_to :voter, polymorphic: true
6
6
 
7
7
  validates_uniqueness_of :voteable_id, scope: :voter_id
8
- validates :value, inclusion: { in: [1, -1] }
8
+ validates :value, inclusion: { in: [1, -1], message: 'should be either 1 or -1' }
9
9
  end
@@ -18,6 +18,7 @@ describe Vote do
18
18
  it 'should fail if the value is other than 1 or -1' do
19
19
  vote = Vote.new(value: 2)
20
20
  vote.valid?.must_equal false
21
+ vote.errors.full_messages.must_include 'Value should be either 1 or -1'
21
22
  end
22
23
 
23
24
  it 'should validate uniqueness of vote for voter and voteable' do
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibham
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.rc1
5
- prerelease: 6
4
+ version: 0.1.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamal El Milahi
@@ -13,7 +13,7 @@ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70226356473360 !ruby/object:Gem::Requirement
16
+ requirement: &70361593621620 !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: :development
23
23
  prerelease: false
24
- version_requirements: *70226356473360
24
+ version_requirements: *70361593621620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70226356471720 !ruby/object:Gem::Requirement
27
+ requirement: &70361593618840 !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: *70226356471720
35
+ version_requirements: *70361593618840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: database_cleaner
38
- requirement: &70226356469800 !ruby/object:Gem::Requirement
38
+ requirement: &70361593617980 !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: *70226356469800
46
+ version_requirements: *70361593617980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &70226356468640 !ruby/object:Gem::Requirement
49
+ requirement: &70361593643540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70226356468640
57
+ version_requirements: *70361593643540
58
58
  description: Voting System for Rails applications
59
59
  email:
60
60
  - jamal@elmilahi.com
@@ -96,9 +96,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>'
99
+ - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
- version: 1.3.1
101
+ version: '0'
102
102
  requirements: []
103
103
  rubyforge_project:
104
104
  rubygems_version: 1.8.17