ibham 0.1.0 → 0.1.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -0
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/Rakefile +3 -4
- data/ibham.gemspec +0 -1
- data/lib/ibham/acts_as_voter.rb +1 -1
- data/lib/ibham/version.rb +1 -1
- data/spec/models/vote_spec.rb +7 -7
- data/spec/modules/acts_as_voteable_spec.rb +7 -7
- data/spec/modules/acts_as_voter_spec.rb +19 -19
- data/spec/spec_helper.rb +4 -3
- metadata +15 -24
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
require '
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
4
|
desc 'Default: run specs.'
|
5
|
-
task :
|
5
|
+
task default: :test
|
6
6
|
|
7
|
-
|
8
|
-
test.rspec_opts = ['--color']
|
7
|
+
Rake::TestTask.new do |test|
|
9
8
|
test.pattern = './spec/**/*_spec.rb'
|
10
9
|
end
|
data/ibham.gemspec
CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |gem|
|
|
19
19
|
|
20
20
|
gem.add_development_dependency 'activerecord'
|
21
21
|
gem.add_development_dependency 'rake'
|
22
|
-
gem.add_development_dependency 'rspec'
|
23
22
|
gem.add_development_dependency 'database_cleaner'
|
24
23
|
gem.add_development_dependency 'sqlite3'
|
25
24
|
end
|
data/lib/ibham/acts_as_voter.rb
CHANGED
data/lib/ibham/version.rb
CHANGED
data/spec/models/vote_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe Vote do
|
4
4
|
let(:user) { User.create!(email: 'foo@example.com') }
|
@@ -7,24 +7,24 @@ describe Vote do
|
|
7
7
|
describe 'Validations' do
|
8
8
|
it 'should be valid if the value is 1' do
|
9
9
|
vote = Vote.new(value: 1)
|
10
|
-
vote.
|
10
|
+
vote.valid?.must_equal true
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should be valid if the value is -1' do
|
14
14
|
vote = Vote.new(value: -1)
|
15
|
-
vote.
|
15
|
+
vote.valid?.must_equal true
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should fail if the value is other than 1 or -1' do
|
19
19
|
vote = Vote.new(value: 2)
|
20
|
-
vote.
|
20
|
+
vote.valid?.must_equal false
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should validate uniqueness of vote for voter and voteable' do
|
24
24
|
user.vote_up(item)
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
Vote.count.must_equal 1
|
26
|
+
user.vote_up(item)
|
27
|
+
Vote.count.must_equal 1
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe 'ActsAsVoteable' do
|
4
4
|
let(:user1) { User.create! }
|
@@ -16,33 +16,33 @@ describe 'ActsAsVoteable' do
|
|
16
16
|
|
17
17
|
describe '#up_votes' do
|
18
18
|
it 'should return the number of positive votes for voteable' do
|
19
|
-
item.up_votes.
|
19
|
+
item.up_votes.must_equal 2
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe '#down_votes' do
|
24
24
|
it 'should return the number of negative votes for voteable' do
|
25
|
-
item.down_votes.
|
25
|
+
item.down_votes.must_equal 1
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '#up_percentage' do
|
30
30
|
it 'should return the percentage of positive votes' do
|
31
|
-
item.up_percentage.
|
31
|
+
item.up_percentage.must_be_close_to 66.6, 0.1
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#down_percentage' do
|
36
36
|
it 'should return the percentage of negative votes' do
|
37
|
-
item.down_percentage.
|
37
|
+
item.down_percentage.must_be_close_to 33.3, 0.1
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should return 100% if the item has 1 negative vote' do
|
41
|
-
item2.down_percentage.
|
41
|
+
item2.down_percentage.must_equal 100
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should return 0 if the item has 0 positive vote' do
|
45
|
-
item2.up_percentage.
|
45
|
+
item2.up_percentage.must_equal 0
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe 'ActsAsVoter' do
|
4
4
|
let(:user) { User.create!(email: 'foo@example.com') }
|
@@ -6,46 +6,46 @@ describe 'ActsAsVoter' do
|
|
6
6
|
|
7
7
|
describe '#can_vote_for?' do
|
8
8
|
it 'should return true if the voter can vote for an item' do
|
9
|
-
user.can_vote_for?(item).
|
9
|
+
user.can_vote_for?(item).must_equal true
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should return false if the voter can not vote for an item' do
|
13
13
|
user.vote_down(item)
|
14
|
-
user.can_vote_for?(item).
|
14
|
+
user.can_vote_for?(item).must_equal false
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '#vote_up' do
|
19
19
|
it 'should create a positive vote' do
|
20
|
-
|
21
|
-
|
20
|
+
vote_count = Vote.count
|
21
|
+
user.vote_up(item)
|
22
|
+
Vote.count.must_equal vote_count + 1
|
23
|
+
Vote.last.value.must_equal 1
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
describe '#vote_down' do
|
26
28
|
it 'should create a positive vote' do
|
27
|
-
|
28
|
-
|
29
|
+
vote_count = Vote.count
|
30
|
+
user.vote_down(item)
|
31
|
+
Vote.count.must_equal vote_count + 1
|
32
|
+
Vote.last.value.must_equal -1
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
32
36
|
describe '#cast_vote' do
|
33
37
|
it 'should create a positive vote' do
|
34
|
-
Vote.count
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end.to change { Vote.count }.by(1)
|
39
|
-
Vote.last.value.should == 1
|
38
|
+
vote_count = Vote.count
|
39
|
+
vote = user.cast_vote(item, 1)
|
40
|
+
Vote.count.must_equal vote_count + 1
|
41
|
+
Vote.last.value.must_equal 1
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'should create a negative vote' do
|
43
|
-
Vote.count
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end.to change { Vote.count }.by(1)
|
48
|
-
Vote.last.value.should == -1
|
45
|
+
vote_count = Vote.count
|
46
|
+
vote = user.cast_vote(item, -1)
|
47
|
+
Vote.count.must_equal vote_count + 1
|
48
|
+
Vote.last.value.must_equal -1
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,7 @@ require 'active_record'
|
|
2
2
|
require 'database_cleaner'
|
3
3
|
require 'sqlite3'
|
4
4
|
require 'ibham'
|
5
|
+
require 'minitest/autorun'
|
5
6
|
|
6
7
|
db_config = {
|
7
8
|
:adapter => 'sqlite3',
|
@@ -12,9 +13,9 @@ ActiveRecord::Base.establish_connection(db_config)
|
|
12
13
|
|
13
14
|
ActiveRecord::Migration.verbose = false
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
class MiniTest::Spec
|
17
|
+
before(:each) { DatabaseCleaner.start }
|
18
|
+
after(:each) { DatabaseCleaner.clean }
|
18
19
|
end
|
19
20
|
|
20
21
|
ActiveRecord::Schema.define do
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibham
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jamal El Milahi
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70226356473360 !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: *
|
24
|
+
version_requirements: *70226356473360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70226356471720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,21 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rspec
|
38
|
-
requirement: &70263820313380 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0'
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *70263820313380
|
35
|
+
version_requirements: *70226356471720
|
47
36
|
- !ruby/object:Gem::Dependency
|
48
37
|
name: database_cleaner
|
49
|
-
requirement: &
|
38
|
+
requirement: &70226356469800 !ruby/object:Gem::Requirement
|
50
39
|
none: false
|
51
40
|
requirements:
|
52
41
|
- - ! '>='
|
@@ -54,10 +43,10 @@ dependencies:
|
|
54
43
|
version: '0'
|
55
44
|
type: :development
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
46
|
+
version_requirements: *70226356469800
|
58
47
|
- !ruby/object:Gem::Dependency
|
59
48
|
name: sqlite3
|
60
|
-
requirement: &
|
49
|
+
requirement: &70226356468640 !ruby/object:Gem::Requirement
|
61
50
|
none: false
|
62
51
|
requirements:
|
63
52
|
- - ! '>='
|
@@ -65,7 +54,7 @@ dependencies:
|
|
65
54
|
version: '0'
|
66
55
|
type: :development
|
67
56
|
prerelease: false
|
68
|
-
version_requirements: *
|
57
|
+
version_requirements: *70226356468640
|
69
58
|
description: Voting System for Rails applications
|
70
59
|
email:
|
71
60
|
- jamal@elmilahi.com
|
@@ -74,6 +63,8 @@ extensions: []
|
|
74
63
|
extra_rdoc_files: []
|
75
64
|
files:
|
76
65
|
- .gitignore
|
66
|
+
- .travis.yml
|
67
|
+
- CHANGELOG.md
|
77
68
|
- Gemfile
|
78
69
|
- LICENSE.txt
|
79
70
|
- README.md
|
@@ -105,9 +96,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
97
|
none: false
|
107
98
|
requirements:
|
108
|
-
- - ! '
|
99
|
+
- - ! '>'
|
109
100
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
101
|
+
version: 1.3.1
|
111
102
|
requirements: []
|
112
103
|
rubyforge_project:
|
113
104
|
rubygems_version: 1.8.17
|