feeder 0.3.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +119 -2
  3. data/app/controllers/feeder/application_controller.rb +1 -1
  4. data/app/controllers/feeder/items_controller.rb +7 -0
  5. data/app/models/feeder/feedable_observer.rb +43 -7
  6. data/app/models/feeder/item.rb +2 -6
  7. data/app/views/feeder/items/_item.html.erb +1 -1
  8. data/app/views/feeder/items/_item.json.jbuilder +1 -0
  9. data/app/views/feeder/{feeds → items}/index.html.erb +1 -1
  10. data/app/views/feeder/items/index.json.jbuilder +1 -0
  11. data/config/routes.rb +1 -1
  12. data/db/migrate/20140321085409_add_sticky_to_feeder_items.rb +5 -0
  13. data/db/migrate/20140401131911_prohibit_null_on_feeder_item_stickies.rb +13 -0
  14. data/db/migrate/20140526110451_add_blocked_to_feeder_items.rb +5 -0
  15. data/db/migrate/20140526110501_add_reported_to_feeder_items.rb +5 -0
  16. data/lib/feeder.rb +18 -2
  17. data/lib/feeder/active_record.rb +9 -0
  18. data/lib/feeder/concerns.rb +6 -0
  19. data/lib/feeder/concerns/controllers.rb +5 -0
  20. data/lib/feeder/concerns/controllers/items_controller.rb +22 -0
  21. data/lib/feeder/concerns/feedable.rb +27 -0
  22. data/lib/feeder/concerns/helpers.rb +5 -0
  23. data/lib/feeder/concerns/helpers/filter.rb +20 -0
  24. data/lib/feeder/concerns/models.rb +5 -0
  25. data/lib/feeder/concerns/models/item.rb +31 -0
  26. data/lib/feeder/configuration.rb +19 -5
  27. data/lib/feeder/engine.rb +3 -2
  28. data/lib/feeder/version.rb +1 -1
  29. data/spec/controllers/feeder/items_controller_spec.rb +36 -0
  30. data/spec/dummy/app/models/message.rb +2 -0
  31. data/spec/dummy/config/initializers/feeder.rb +1 -1
  32. data/spec/dummy/db/development.sqlite3 +0 -0
  33. data/spec/dummy/db/schema.rb +4 -1
  34. data/spec/dummy/db/test.sqlite3 +0 -0
  35. data/spec/dummy/log/development.log +359 -0
  36. data/spec/dummy/log/test.log +53050 -0
  37. data/spec/factories/feeder/items.rb +10 -0
  38. data/spec/lib/feeder/concerns/feedable_spec.rb +33 -0
  39. data/spec/lib/feeder/configuration_spec.rb +6 -6
  40. data/spec/lib/feeder_spec.rb +14 -2
  41. data/spec/models/feeder/feedable_observer_spec.rb +95 -0
  42. data/spec/models/feeder/item_spec.rb +38 -0
  43. data/spec/spec_helper.rb +4 -0
  44. data/spec/support/shared_examples/filterable.rb +48 -0
  45. metadata +97 -39
  46. data/app/controllers/feeder/feeds_controller.rb +0 -9
  47. data/app/views/layouts/feeder/application.html.erb +0 -14
  48. data/spec/controllers/feeder/feeds_controller_spec.rb +0 -27
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :feeder_item, class: 'Feeder::Item' do
4
+ feedable nil
5
+
6
+ trait(:published) { published_at 1.day.ago }
7
+ trait(:sticky) { sticky true }
8
+ end
9
+
10
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Feeder::Concerns::Feedable do
4
+ subject { Message.new }
5
+
6
+ it 'responds to sticky' do
7
+ expect(subject).to respond_to :sticky
8
+ end
9
+
10
+ it 'responds to sticky=' do
11
+ expect(subject).to respond_to :sticky=
12
+ end
13
+
14
+ context 'with a feeder item' do
15
+ before do
16
+ expect(subject).to receive(:feeder_item).and_return(double sticky: true).at_least(1).times
17
+ end
18
+
19
+ it 'delegates sticky to it' do
20
+ expect(subject.sticky).to eq true
21
+ end
22
+ end
23
+
24
+ context 'without a feeder item' do
25
+ before do
26
+ expect(subject).to receive(:feeder_item).and_return(nil).at_least(1).times
27
+ end
28
+
29
+ it 'mainstains state internally' do
30
+ expect(subject.sticky).to eq false
31
+ end
32
+ end
33
+ end
@@ -2,18 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe Feeder::Configuration do
4
4
  it "sets the observers to an empty array upon initialization" do
5
- expect(subject.observables).to eq [ ]
5
+ expect(subject.observables).to eq({})
6
6
  end
7
7
 
8
- it "sets a default sort order upon initialization" do
9
- expect(subject.sort_order).to eq({ created_at: :desc })
8
+ it "sets default scopes order upon initialization" do
9
+ expect(subject.scopes.count).to eq 1
10
10
  end
11
11
 
12
- describe "#add_observable" do
12
+ describe ".observe" do
13
13
  it "adds an observable to @observables" do
14
- subject.add_observable "SomeObservable"
14
+ subject.observe "SomeObservable"
15
15
 
16
- expect(subject.observables).to match_array [ "SomeObservable" ]
16
+ expect(subject.observables).to eq({ "SomeObservable" => {} })
17
17
  end
18
18
  end
19
19
  end
@@ -7,8 +7,8 @@ describe Feeder do
7
7
 
8
8
  describe ".configure" do
9
9
  context "when no block is given" do
10
- it "raises an error" do
11
- expect { subject.configure }.to raise_error ArgumentError
10
+ it "does nothing" do
11
+ expect(subject.configure).to be nil
12
12
  end
13
13
  end
14
14
 
@@ -20,4 +20,16 @@ describe Feeder do
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ describe '.temporarily' do
25
+ it 'sets temporary configuration options' do
26
+ expect(Feeder.config.scopes.count).to eq 1
27
+
28
+ Feeder.temporarily scopes: [] do
29
+ expect(Feeder.config.scopes.count).to eq 0
30
+ end
31
+
32
+ expect(Feeder.config.scopes.count).to eq 1
33
+ end
34
+ end
23
35
  end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Feeder::FeedableObserver do
4
+ subject { described_class.instance }
5
+
6
+ let(:message) { create :message }
7
+
8
+ around do |example|
9
+ Timecop.freeze Time.now do
10
+ example.run
11
+ end
12
+ end
13
+
14
+ describe '.after_save' do
15
+ context 'with a message that is no longer sticky' do
16
+ let(:message) { create :message, sticky: true }
17
+
18
+ before do
19
+ subject.after_create message
20
+
21
+ message.update sticky: false
22
+
23
+ subject.after_save message
24
+ end
25
+
26
+ it 'should update the feeder item to no longer be sticky' do
27
+ expect(message.feeder_item.sticky).to eq false
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '.after_create' do
33
+ before do
34
+ subject.after_create message
35
+ end
36
+
37
+ it 'creates a new feed item' do
38
+ expect(Feeder::Item.count).to eq 1
39
+ end
40
+
41
+ it 'refers to the feedable' do
42
+ expect(Feeder::Item.last.feedable).to eq message
43
+ end
44
+
45
+ it 'mirrors the created time' do
46
+ expect(Feeder::Item.last.created_at.to_i).to eq message.created_at.to_i
47
+ end
48
+
49
+ it 'sets published_at to the current time' do
50
+ expect(Feeder::Item.last.published_at.to_i).to eq Time.zone.now.to_i
51
+ end
52
+
53
+ context 'when the feedable is sticky' do
54
+ let(:message) { create :message, sticky: true }
55
+
56
+ it 'stickies' do
57
+ expect(Feeder::Item.last.sticky).to eq true
58
+ end
59
+ end
60
+
61
+ context 'when the feedable is not sticky' do
62
+ let(:message) { create :message, sticky: false }
63
+
64
+ it 'does not sticky' do
65
+ expect(Feeder::Item.last.sticky).to eq false
66
+ end
67
+ end
68
+
69
+ context 'when the feedable is configured to not feed' do
70
+ context 'with a lambda' do
71
+ around do |example|
72
+ Feeder.temporarily observables: { Message => { if: -> message { message.nil? }} } do
73
+ example.run
74
+ end
75
+ end
76
+
77
+ it 'does not create a feed item' do
78
+ expect(Feeder::Item.count).to eq 0
79
+ end
80
+ end
81
+
82
+ context 'with a symbol' do
83
+ around do |example|
84
+ Feeder.temporarily observables: { Message => { if: :nil? } } do
85
+ example.run
86
+ end
87
+ end
88
+
89
+ it 'does not create a feed item' do
90
+ expect(Feeder::Item.count).to eq 0
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  module Feeder
4
4
  describe Item do
5
+ it_behaves_like "a filterable"
6
+
5
7
  describe "#type" do
6
8
  it "returns the lowercase version of the feedable's type, separating words with an underscore" do
7
9
  subject.stub(:feedable_type).and_return "SomeFeedable"
@@ -15,5 +17,41 @@ module Feeder
15
17
  end
16
18
  end
17
19
  end
20
+
21
+ describe "#report" do
22
+ subject { create :feeder_item, reported: false }
23
+
24
+ it "ensures the item is reported" do
25
+ subject.report
26
+ expect(subject).to be_reported
27
+ end
28
+ end
29
+
30
+ describe "#block" do
31
+ subject { create :feeder_item, blocked: false }
32
+
33
+ it "ensures the item is blocked" do
34
+ subject.block
35
+ expect(subject).to be_blocked
36
+ end
37
+ end
38
+
39
+ describe "#unreport" do
40
+ subject { create :feeder_item, reported: true }
41
+
42
+ it "ensures the item is not reported" do
43
+ subject.unreport
44
+ expect(subject).not_to be_reported
45
+ end
46
+ end
47
+
48
+ describe "#unblock" do
49
+ subject { create :feeder_item, blocked: true }
50
+
51
+ it "ensures the item is not blocked" do
52
+ subject.unblock
53
+ expect(subject).not_to be_blocked
54
+ end
55
+ end
18
56
  end
19
57
  end
@@ -4,12 +4,16 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'rspec/autorun'
6
6
  require 'factory_girl_rails'
7
+ require 'timecop'
7
8
 
8
9
  Rails.backtrace_cleaner.remove_silencers!
9
10
 
10
11
  # Load support files
11
12
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
13
 
14
+ # Load dummy files
15
+ Dir["#{File.dirname(__FILE__)}/dummy/spec/factories/**/*.rb"].each { |f| require f }
16
+
13
17
  RSpec.configure do |config|
14
18
  config.mock_with :rspec
15
19
  config.use_transactional_fixtures = true
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples "a filterable" do
4
+ subject { described_class }
5
+
6
+ describe "::filter" do
7
+ context "when provided a hash" do
8
+ let(:left) { create_list :feeder_item, 1 }
9
+ let(:arguments) { { Feeder::Item => right } }
10
+
11
+ context "and the value being a list of IDs" do
12
+ let(:right) { left.map &:id }
13
+
14
+ let!(:expected) do
15
+ left.each.map do |feedable|
16
+ create :feeder_item, feedable: feedable
17
+ end
18
+ end
19
+
20
+ before do
21
+ others = create_list :feeder_item, 1
22
+ others.each { |feedable| create :feeder_item, feedable: feedable }
23
+ end
24
+
25
+ it "fetches only items based on the filter" do
26
+ expect(subject.filter arguments).to match_array expected
27
+ end
28
+ end
29
+
30
+ context "and the value being :all" do
31
+ let(:right) { :all }
32
+
33
+ let!(:expected) do
34
+ Feeder::Item.where feedable_type: "Feeder::Item"
35
+ end
36
+
37
+ before do
38
+ others = create_list :feeder_item, 1
39
+ others.each { |feedable| create :feeder_item, feedable: feedable }
40
+ end
41
+
42
+ it "fetches only items based on the filter" do
43
+ expect(subject.filter arguments).to match_array expected
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feeder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sindre Moen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-17 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: kaminari
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sqlite3
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: |
112
140
  Feeder gives you a mountable engine that provides a route to a feed page in your
113
141
  Ruby on Rails application.
@@ -122,22 +150,36 @@ files:
122
150
  - app/assets/javascripts/feeder/application.js
123
151
  - app/assets/stylesheets/feeder/application.css
124
152
  - app/controllers/feeder/application_controller.rb
125
- - app/controllers/feeder/feeds_controller.rb
153
+ - app/controllers/feeder/items_controller.rb
126
154
  - app/helpers/feeder/application_helper.rb
127
155
  - app/helpers/feeder/feeds_helper.rb
128
156
  - app/models/feeder/feedable_observer.rb
129
157
  - app/models/feeder/item.rb
130
- - app/views/feeder/feeds/index.html.erb
131
158
  - app/views/feeder/items/_item.html.erb
132
- - app/views/layouts/feeder/application.html.erb
159
+ - app/views/feeder/items/_item.json.jbuilder
160
+ - app/views/feeder/items/index.html.erb
161
+ - app/views/feeder/items/index.json.jbuilder
133
162
  - config/routes.rb
134
163
  - db/migrate/20140317150822_create_feeder_items.rb
135
164
  - db/migrate/20140317152137_add_polymorphic_feedable_reference_to_feeder_items.rb
165
+ - db/migrate/20140321085409_add_sticky_to_feeder_items.rb
166
+ - db/migrate/20140401131911_prohibit_null_on_feeder_item_stickies.rb
167
+ - db/migrate/20140526110451_add_blocked_to_feeder_items.rb
168
+ - db/migrate/20140526110501_add_reported_to_feeder_items.rb
136
169
  - lib/feeder.rb
170
+ - lib/feeder/active_record.rb
171
+ - lib/feeder/concerns.rb
172
+ - lib/feeder/concerns/controllers.rb
173
+ - lib/feeder/concerns/controllers/items_controller.rb
174
+ - lib/feeder/concerns/feedable.rb
175
+ - lib/feeder/concerns/helpers.rb
176
+ - lib/feeder/concerns/helpers/filter.rb
177
+ - lib/feeder/concerns/models.rb
178
+ - lib/feeder/concerns/models/item.rb
137
179
  - lib/feeder/configuration.rb
138
180
  - lib/feeder/engine.rb
139
181
  - lib/feeder/version.rb
140
- - spec/controllers/feeder/feeds_controller_spec.rb
182
+ - spec/controllers/feeder/items_controller_spec.rb
141
183
  - spec/dummy/README.md
142
184
  - spec/dummy/Rakefile
143
185
  - spec/dummy/app/assets/javascripts/application.js
@@ -169,19 +211,27 @@ files:
169
211
  - spec/dummy/config/initializers/wrap_parameters.rb
170
212
  - spec/dummy/config/locales/en.yml
171
213
  - spec/dummy/config/routes.rb
214
+ - spec/dummy/db/development.sqlite3
172
215
  - spec/dummy/db/migrate/20140317152438_create_messages.rb
173
216
  - spec/dummy/db/schema.rb
217
+ - spec/dummy/db/test.sqlite3
218
+ - spec/dummy/log/development.log
219
+ - spec/dummy/log/test.log
174
220
  - spec/dummy/public/404.html
175
221
  - spec/dummy/public/422.html
176
222
  - spec/dummy/public/500.html
177
223
  - spec/dummy/public/favicon.ico
178
224
  - spec/dummy/spec/factories/messages.rb
179
225
  - spec/dummy/spec/models/message_spec.rb
226
+ - spec/factories/feeder/items.rb
227
+ - spec/lib/feeder/concerns/feedable_spec.rb
180
228
  - spec/lib/feeder/configuration_spec.rb
181
229
  - spec/lib/feeder_spec.rb
230
+ - spec/models/feeder/feedable_observer_spec.rb
182
231
  - spec/models/feeder/item_spec.rb
183
232
  - spec/spec_helper.rb
184
233
  - spec/support/observers.rb
234
+ - spec/support/shared_examples/filterable.rb
185
235
  homepage: http://github.com/hyperoslo/feeder
186
236
  licenses:
187
237
  - MIT
@@ -202,53 +252,61 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
252
  version: '0'
203
253
  requirements: []
204
254
  rubyforge_project:
205
- rubygems_version: 2.2.0
255
+ rubygems_version: 2.2.2
206
256
  signing_key:
207
257
  specification_version: 4
208
258
  summary: Provides simple feed functionality through an engine
209
259
  test_files:
210
- - spec/controllers/feeder/feeds_controller_spec.rb
211
- - spec/spec_helper.rb
212
- - spec/lib/feeder_spec.rb
213
- - spec/lib/feeder/configuration_spec.rb
214
- - spec/support/observers.rb
215
- - spec/dummy/public/422.html
216
- - spec/dummy/public/500.html
217
- - spec/dummy/public/favicon.ico
218
- - spec/dummy/public/404.html
260
+ - spec/controllers/feeder/items_controller_spec.rb
261
+ - spec/dummy/app/assets/javascripts/application.js
262
+ - spec/dummy/app/assets/stylesheets/application.css
263
+ - spec/dummy/app/controllers/application_controller.rb
264
+ - spec/dummy/app/helpers/application_helper.rb
265
+ - spec/dummy/app/models/message.rb
266
+ - spec/dummy/app/views/feeder/types/_message.html.erb
267
+ - spec/dummy/app/views/layouts/application.html.erb
268
+ - spec/dummy/bin/bundle
269
+ - spec/dummy/bin/rails
270
+ - spec/dummy/bin/rake
219
271
  - spec/dummy/config/application.rb
220
- - spec/dummy/config/initializers/feeder.rb
272
+ - spec/dummy/config/boot.rb
273
+ - spec/dummy/config/database.yml
274
+ - spec/dummy/config/environment.rb
275
+ - spec/dummy/config/environments/development.rb
276
+ - spec/dummy/config/environments/production.rb
277
+ - spec/dummy/config/environments/test.rb
278
+ - spec/dummy/config/initializers/backtrace_silencers.rb
221
279
  - spec/dummy/config/initializers/cookies_serializer.rb
222
- - spec/dummy/config/initializers/session_store.rb
223
- - spec/dummy/config/initializers/mime_types.rb
224
- - spec/dummy/config/initializers/wrap_parameters.rb
280
+ - spec/dummy/config/initializers/feeder.rb
281
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
225
282
  - spec/dummy/config/initializers/inflections.rb
283
+ - spec/dummy/config/initializers/mime_types.rb
226
284
  - spec/dummy/config/initializers/secret_token.rb
227
- - spec/dummy/config/initializers/backtrace_silencers.rb
228
- - spec/dummy/config/initializers/filter_parameter_logging.rb
229
- - spec/dummy/config/environments/production.rb
230
- - spec/dummy/config/environments/test.rb
231
- - spec/dummy/config/environments/development.rb
285
+ - spec/dummy/config/initializers/session_store.rb
286
+ - spec/dummy/config/initializers/wrap_parameters.rb
232
287
  - spec/dummy/config/locales/en.yml
233
- - spec/dummy/config/database.yml
234
- - spec/dummy/config/environment.rb
235
- - spec/dummy/config/boot.rb
236
288
  - spec/dummy/config/routes.rb
237
289
  - spec/dummy/config.ru
238
- - spec/dummy/README.md
290
+ - spec/dummy/db/development.sqlite3
239
291
  - spec/dummy/db/migrate/20140317152438_create_messages.rb
240
292
  - spec/dummy/db/schema.rb
241
- - spec/dummy/bin/rails
242
- - spec/dummy/bin/bundle
243
- - spec/dummy/bin/rake
293
+ - spec/dummy/db/test.sqlite3
294
+ - spec/dummy/log/development.log
295
+ - spec/dummy/log/test.log
296
+ - spec/dummy/public/404.html
297
+ - spec/dummy/public/422.html
298
+ - spec/dummy/public/500.html
299
+ - spec/dummy/public/favicon.ico
244
300
  - spec/dummy/Rakefile
245
- - spec/dummy/app/assets/javascripts/application.js
246
- - spec/dummy/app/assets/stylesheets/application.css
247
- - spec/dummy/app/controllers/application_controller.rb
248
- - spec/dummy/app/helpers/application_helper.rb
249
- - spec/dummy/app/views/feeder/types/_message.html.erb
250
- - spec/dummy/app/views/layouts/application.html.erb
251
- - spec/dummy/app/models/message.rb
301
+ - spec/dummy/README.md
252
302
  - spec/dummy/spec/factories/messages.rb
253
303
  - spec/dummy/spec/models/message_spec.rb
304
+ - spec/factories/feeder/items.rb
305
+ - spec/lib/feeder/concerns/feedable_spec.rb
306
+ - spec/lib/feeder/configuration_spec.rb
307
+ - spec/lib/feeder_spec.rb
308
+ - spec/models/feeder/feedable_observer_spec.rb
254
309
  - spec/models/feeder/item_spec.rb
310
+ - spec/spec_helper.rb
311
+ - spec/support/observers.rb
312
+ - spec/support/shared_examples/filterable.rb