acts_as_previous_next 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +145 -0
- data/Guardfile +19 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +50 -0
- data/Rakefile +27 -0
- data/acts_as_previous_next.gemspec +31 -0
- data/lib/acts_as_previous_next/version.rb +3 -0
- data/lib/acts_as_previous_next.rb +46 -0
- data/lib/tasks/acts_as_previous_next_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/ability.rb +12 -0
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/models/without_cancan.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +42 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20120104174603_create_posts.rb +9 -0
- data/spec/dummy/db/migrate/20120105104935_create_users.rb +9 -0
- data/spec/dummy/db/migrate/20120105110842_create_without_cancans.rb +9 -0
- data/spec/dummy/db/schema.rb +37 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/post.rb +13 -0
- data/spec/factories/user.rb +11 -0
- data/spec/factories/without_cancan.rb +11 -0
- data/spec/models/post_spec.rb +97 -0
- data/spec/models/without_cancan_spec.rb +50 -0
- data/spec/spec_helper.rb +80 -0
- metadata +166 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Post do
|
4
|
+
|
5
|
+
let(:fp1) { FactoryGirl.build(:first_post) }
|
6
|
+
let(:fp2) { FactoryGirl.build(:second_post) }
|
7
|
+
|
8
|
+
context 'with current ability as admin' do
|
9
|
+
|
10
|
+
let(:admin) { FactoryGirl.build(:admin) }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@current_ability = Ability.new(admin)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return nil on next if no objects exists' do
|
17
|
+
fp1.next(@current_ability).should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return nil on previous if no objects exists' do
|
21
|
+
fp1.previous(@current_ability).should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return self on next if one object exists' do
|
25
|
+
fp1.save
|
26
|
+
fp1.next(@current_ability).should eq(fp1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return self on previous if one object exists' do
|
30
|
+
fp1.save
|
31
|
+
fp1.previous(@current_ability).should eq(fp1)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return valid next object ' do
|
35
|
+
fp1.save
|
36
|
+
fp2.save
|
37
|
+
fp1.next(@current_ability).should eq(fp2)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return valid previous object' do
|
41
|
+
fp1.save
|
42
|
+
fp2.save
|
43
|
+
fp2.previous(@current_ability).should eq(fp1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return self if next is called on previous' do
|
47
|
+
fp1.save
|
48
|
+
fp2.save
|
49
|
+
fp1.previous(@current_ability).next(@current_ability).should eq(fp1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should return self if previous is called on next' do
|
53
|
+
fp1.save
|
54
|
+
fp2.save
|
55
|
+
fp1.next(@current_ability).previous(@current_ability).should eq(fp1)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with current ability as user' do
|
61
|
+
|
62
|
+
let(:admin) { FactoryGirl.build(:admin) }
|
63
|
+
let(:user) { FactoryGirl.build(:user) }
|
64
|
+
let(:fp3) { FactoryGirl.build(:third_post) }
|
65
|
+
|
66
|
+
before(:each) do
|
67
|
+
admin.save
|
68
|
+
user.save
|
69
|
+
fp1.user_id = user.id
|
70
|
+
fp3.user_id = user.id
|
71
|
+
fp2.user_id = admin.id
|
72
|
+
fp1.save
|
73
|
+
fp2.save
|
74
|
+
fp3.save
|
75
|
+
@current_ability = Ability.new(user)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should not reach invalid next object' do
|
79
|
+
fp1.next(@current_ability).should_not eq(fp2)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should not reach invalid previous object' do
|
83
|
+
fp3.previous(@current_ability).should_not eq(fp2)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should reach valid next object' do
|
87
|
+
fp1.next(@current_ability).should eq(fp3)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should reach valid previous object' do
|
91
|
+
fp3.previous(@current_ability).should eq(fp1)
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WithoutCancan do
|
4
|
+
|
5
|
+
let(:wc1) { FactoryGirl.build(:wc1) }
|
6
|
+
let(:wc2) { FactoryGirl.build(:wc2) }
|
7
|
+
|
8
|
+
it 'should return nil on next if no objects exists' do
|
9
|
+
wc1.next.should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return nil on previous if no objects exists' do
|
13
|
+
wc1.previous.should be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return self on next if one object exists' do
|
17
|
+
wc1.save
|
18
|
+
wc1.next.should eq(wc1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return self on previous if one object exists' do
|
22
|
+
wc1.save
|
23
|
+
wc1.previous.should eq(wc1)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return valid next object ' do
|
27
|
+
wc1.save
|
28
|
+
wc2.save
|
29
|
+
wc1.next.should eq(wc2)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return valid previous object' do
|
33
|
+
wc1.save
|
34
|
+
wc2.save
|
35
|
+
wc2.previous.should eq(wc1)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return self if next is called on previous' do
|
39
|
+
wc1.save
|
40
|
+
wc2.save
|
41
|
+
wc1.previous.next.should eq(wc1)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return self if previous is called on next' do
|
45
|
+
wc1.save
|
46
|
+
wc2.save
|
47
|
+
wc1.next.previous.should eq(wc1)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
3
|
+
require 'factory_girl'
|
4
|
+
require 'database_cleaner'
|
5
|
+
|
6
|
+
Spork.prefork do
|
7
|
+
# Loading more in this block will cause your tests to run faster. However,
|
8
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
9
|
+
# need to restart spork for it take effect.
|
10
|
+
ENV["RAILS_ENV"] ||= 'test'
|
11
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
12
|
+
|
13
|
+
require 'rspec/rails'
|
14
|
+
|
15
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
16
|
+
# in spec/support/ and its subdirectories.
|
17
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# == Mock Framework
|
21
|
+
#
|
22
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
23
|
+
#
|
24
|
+
# config.mock_with :mocha
|
25
|
+
# config.mock_with :flexmock
|
26
|
+
# config.mock_with :rr
|
27
|
+
config.mock_with :rspec
|
28
|
+
|
29
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
30
|
+
# examples within a transaction, remove the following line or assign false
|
31
|
+
# instead of true.
|
32
|
+
config.use_transactional_fixtures = false
|
33
|
+
|
34
|
+
# If true, the base class of anonymous controllers will be inferred
|
35
|
+
# automatically. This will be the default behavior in future versions of
|
36
|
+
# rspec-rails.
|
37
|
+
config.infer_base_class_for_anonymous_controllers = false
|
38
|
+
|
39
|
+
config.use_instantiated_fixtures = false
|
40
|
+
|
41
|
+
# Use DatabaseCleaner to enable js testing
|
42
|
+
config.before(:suite) do
|
43
|
+
DatabaseCleaner.strategy = :truncation
|
44
|
+
DatabaseCleaner.clean_with(:truncation)
|
45
|
+
end
|
46
|
+
|
47
|
+
config.before(:each) do
|
48
|
+
#Timecop.return
|
49
|
+
DatabaseCleaner.start
|
50
|
+
end
|
51
|
+
|
52
|
+
config.after(:each) do
|
53
|
+
DatabaseCleaner.clean
|
54
|
+
end
|
55
|
+
|
56
|
+
config.before(:all) do
|
57
|
+
#DeferredGarbageCollection.start
|
58
|
+
end
|
59
|
+
|
60
|
+
config.after(:all) do
|
61
|
+
#DeferredGarbageCollection.reconsider
|
62
|
+
end
|
63
|
+
|
64
|
+
# Add helpers for devise authentication
|
65
|
+
#config.include Devise::TestHelpers, type: :controller
|
66
|
+
#config.extend ControllerMacros, type: :controller
|
67
|
+
|
68
|
+
# Also include warden
|
69
|
+
#config.include Warden::Test::Helpers
|
70
|
+
#config.after(:each) { Warden.test_reset!}
|
71
|
+
|
72
|
+
# Include factory_girl's helpers
|
73
|
+
#config.include FactoryGirl::Syntax::Methods
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
Spork.each_run do
|
78
|
+
FactoryGirl.find_definitions
|
79
|
+
end
|
80
|
+
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_previous_next
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Giorgos Tsiftsis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &14179180 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0.rc2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *14179180
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mysql2
|
27
|
+
requirement: &14178700 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *14178700
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: factory_girl_rails
|
38
|
+
requirement: &14178040 !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: *14178040
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: spork
|
49
|
+
requirement: &14177240 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - =
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.0.rc9
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *14177240
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard-rspec
|
60
|
+
requirement: &14176500 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *14176500
|
69
|
+
description: ! "This 'acts_as' extension provides the capability for having previous
|
70
|
+
next methods for object.\n Previous & next are based on a specified column (default
|
71
|
+
is id)."
|
72
|
+
email:
|
73
|
+
- giorgos.tsiftsis@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- Guardfile
|
83
|
+
- MIT-LICENSE
|
84
|
+
- README.rdoc
|
85
|
+
- Rakefile
|
86
|
+
- acts_as_previous_next.gemspec
|
87
|
+
- lib/acts_as_previous_next.rb
|
88
|
+
- lib/acts_as_previous_next/version.rb
|
89
|
+
- lib/tasks/acts_as_previous_next_tasks.rake
|
90
|
+
- spec/dummy/README.rdoc
|
91
|
+
- spec/dummy/Rakefile
|
92
|
+
- spec/dummy/app/assets/javascripts/application.js
|
93
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
94
|
+
- spec/dummy/app/controllers/application_controller.rb
|
95
|
+
- spec/dummy/app/helpers/application_helper.rb
|
96
|
+
- spec/dummy/app/mailers/.gitkeep
|
97
|
+
- spec/dummy/app/models/.gitkeep
|
98
|
+
- spec/dummy/app/models/ability.rb
|
99
|
+
- spec/dummy/app/models/post.rb
|
100
|
+
- spec/dummy/app/models/user.rb
|
101
|
+
- spec/dummy/app/models/without_cancan.rb
|
102
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
103
|
+
- spec/dummy/config.ru
|
104
|
+
- spec/dummy/config/application.rb
|
105
|
+
- spec/dummy/config/boot.rb
|
106
|
+
- spec/dummy/config/database.yml
|
107
|
+
- spec/dummy/config/environment.rb
|
108
|
+
- spec/dummy/config/environments/development.rb
|
109
|
+
- spec/dummy/config/environments/production.rb
|
110
|
+
- spec/dummy/config/environments/test.rb
|
111
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
112
|
+
- spec/dummy/config/initializers/inflections.rb
|
113
|
+
- spec/dummy/config/initializers/mime_types.rb
|
114
|
+
- spec/dummy/config/initializers/secret_token.rb
|
115
|
+
- spec/dummy/config/initializers/session_store.rb
|
116
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
117
|
+
- spec/dummy/config/locales/en.yml
|
118
|
+
- spec/dummy/config/routes.rb
|
119
|
+
- spec/dummy/db/migrate/20120104174603_create_posts.rb
|
120
|
+
- spec/dummy/db/migrate/20120105104935_create_users.rb
|
121
|
+
- spec/dummy/db/migrate/20120105110842_create_without_cancans.rb
|
122
|
+
- spec/dummy/db/schema.rb
|
123
|
+
- spec/dummy/lib/assets/.gitkeep
|
124
|
+
- spec/dummy/log/.gitkeep
|
125
|
+
- spec/dummy/public/404.html
|
126
|
+
- spec/dummy/public/422.html
|
127
|
+
- spec/dummy/public/500.html
|
128
|
+
- spec/dummy/public/favicon.ico
|
129
|
+
- spec/dummy/script/rails
|
130
|
+
- spec/factories/post.rb
|
131
|
+
- spec/factories/user.rb
|
132
|
+
- spec/factories/without_cancan.rb
|
133
|
+
- spec/models/post_spec.rb
|
134
|
+
- spec/models/without_cancan_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
homepage: ''
|
137
|
+
licenses: []
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
hash: 1614502978542647
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
hash: 1614502978542647
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 1.8.10
|
163
|
+
signing_key:
|
164
|
+
specification_version: 3
|
165
|
+
summary: A gem allowing an actire_record model to have previous, next based on a column.
|
166
|
+
test_files: []
|