lazy_crud 0.9.8.0 → 0.9.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -0
  3. data/.gitignore +0 -0
  4. data/.travis.yml +0 -0
  5. data/Gemfile +0 -0
  6. data/Gemfile.lock +0 -3
  7. data/LICENSE +0 -0
  8. data/README.md +33 -20
  9. data/Rakefile +0 -0
  10. data/lazy_crud.gemspec +0 -0
  11. data/lib/lazy_crud/before_hook_methods.rb +0 -0
  12. data/lib/lazy_crud/class_methods.rb +6 -1
  13. data/lib/lazy_crud/constants.rb +0 -0
  14. data/lib/lazy_crud/instance_methods.rb +0 -0
  15. data/lib/lazy_crud/version.rb +1 -1
  16. data/lib/lazy_crud.rb +0 -0
  17. data/lib/responders/json_responder.rb +0 -0
  18. data/spec/integration/discounts_controller_spec.rb +0 -0
  19. data/spec/integration/event_discounts_controller_spec.rb +35 -0
  20. data/spec/integration/events_controller_spec.rb +0 -0
  21. data/spec/integration/hosted_events_discount_controller_spec.rb +35 -0
  22. data/spec/integration/users_controller_spec.rb +0 -0
  23. data/spec/rails_helper.rb +0 -0
  24. data/spec/spec_helper.rb +0 -0
  25. data/spec/support/factories.rb +0 -0
  26. data/spec/support/factory_girl.rb +0 -0
  27. data/spec/support/rails_app/Rakefile +0 -0
  28. data/spec/support/rails_app/app/assets/images/.keep +0 -0
  29. data/spec/support/rails_app/app/assets/javascripts/application.js +0 -0
  30. data/spec/support/rails_app/app/assets/javascripts/some_resources.js +0 -0
  31. data/spec/support/rails_app/app/assets/javascripts/users.js +0 -0
  32. data/spec/support/rails_app/app/assets/stylesheets/application.css +0 -0
  33. data/spec/support/rails_app/app/assets/stylesheets/scaffold.css +0 -0
  34. data/spec/support/rails_app/app/assets/stylesheets/some_resources.css +0 -0
  35. data/spec/support/rails_app/app/assets/stylesheets/users.css +0 -0
  36. data/spec/support/rails_app/app/controllers/application_controller.rb +0 -0
  37. data/spec/support/rails_app/app/controllers/discounts_controller.rb +0 -0
  38. data/spec/support/rails_app/app/controllers/event/discounts_controller.rb +7 -0
  39. data/spec/support/rails_app/app/controllers/events_controller.rb +0 -0
  40. data/spec/support/rails_app/app/controllers/hosted_events/discounts_controller.rb +13 -0
  41. data/spec/support/rails_app/app/controllers/users_controller.rb +0 -0
  42. data/spec/support/rails_app/app/helpers/application_helper.rb +0 -0
  43. data/spec/support/rails_app/app/helpers/events_helper.rb +0 -0
  44. data/spec/support/rails_app/app/helpers/users_helper.rb +0 -0
  45. data/spec/support/rails_app/app/models/collaboration.rb +0 -0
  46. data/spec/support/rails_app/app/models/concerns/.keep +0 -0
  47. data/spec/support/rails_app/app/models/discount.rb +0 -0
  48. data/spec/support/rails_app/app/models/event.rb +0 -0
  49. data/spec/support/rails_app/app/models/user.rb +0 -0
  50. data/spec/support/rails_app/app/views/discounts/edit.html.erb +0 -0
  51. data/spec/support/rails_app/app/views/discounts/index.html.erb +0 -0
  52. data/spec/support/rails_app/app/views/discounts/new.html.erb +0 -0
  53. data/spec/support/rails_app/app/views/discounts/show.html.erb +0 -0
  54. data/spec/support/rails_app/app/views/events/_form.html.erb +0 -0
  55. data/spec/support/rails_app/app/views/events/discounts/edit.html.erb +0 -0
  56. data/spec/support/rails_app/app/views/events/discounts/index.html.erb +0 -0
  57. data/spec/support/rails_app/app/views/events/discounts/new.html.erb +0 -0
  58. data/spec/support/rails_app/app/views/events/discounts/show.html.erb +0 -0
  59. data/spec/support/rails_app/app/views/events/edit.html.erb +0 -0
  60. data/spec/support/rails_app/app/views/events/index.html.erb +0 -0
  61. data/spec/support/rails_app/app/views/events/new.html.erb +0 -0
  62. data/spec/support/rails_app/app/views/events/show.html.erb +0 -0
  63. data/spec/support/rails_app/app/views/hosted_events/discounts/edit.html.erb +0 -0
  64. data/spec/support/rails_app/app/views/hosted_events/discounts/index.html.erb +0 -0
  65. data/spec/support/rails_app/app/views/hosted_events/discounts/new.html.erb +0 -0
  66. data/spec/support/rails_app/app/views/hosted_events/discounts/show.html.erb +0 -0
  67. data/spec/support/rails_app/app/views/layouts/application.html.erb +0 -0
  68. data/spec/support/rails_app/app/views/users/_form.html.erb +0 -0
  69. data/spec/support/rails_app/app/views/users/edit.html.erb +0 -0
  70. data/spec/support/rails_app/app/views/users/index.html.erb +0 -0
  71. data/spec/support/rails_app/app/views/users/new.html.erb +0 -0
  72. data/spec/support/rails_app/app/views/users/show.html.erb +0 -0
  73. data/spec/support/rails_app/config/application.rb +0 -0
  74. data/spec/support/rails_app/config/boot.rb +0 -0
  75. data/spec/support/rails_app/config/database.yml +0 -0
  76. data/spec/support/rails_app/config/environment.rb +0 -0
  77. data/spec/support/rails_app/config/environments/development.rb +0 -0
  78. data/spec/support/rails_app/config/environments/production.rb +0 -0
  79. data/spec/support/rails_app/config/environments/test.rb +0 -0
  80. data/spec/support/rails_app/config/initializers/assets.rb +0 -0
  81. data/spec/support/rails_app/config/initializers/backtrace_silencers.rb +0 -0
  82. data/spec/support/rails_app/config/initializers/cookies_serializer.rb +0 -0
  83. data/spec/support/rails_app/config/initializers/filter_parameter_logging.rb +0 -0
  84. data/spec/support/rails_app/config/initializers/inflections.rb +0 -0
  85. data/spec/support/rails_app/config/initializers/mime_types.rb +0 -0
  86. data/spec/support/rails_app/config/initializers/session_store.rb +0 -0
  87. data/spec/support/rails_app/config/initializers/wrap_parameters.rb +0 -0
  88. data/spec/support/rails_app/config/locales/en.yml +0 -0
  89. data/spec/support/rails_app/config/routes.rb +11 -5
  90. data/spec/support/rails_app/config/secrets.yml +0 -0
  91. data/spec/support/rails_app/config.ru +0 -0
  92. data/spec/support/rails_app/db/development.sqlite3 +0 -0
  93. data/spec/support/rails_app/db/migrate/20141231134904_create_users.rb +0 -0
  94. data/spec/support/rails_app/db/migrate/20150102225507_create_events.rb +0 -0
  95. data/spec/support/rails_app/db/migrate/20150104171110_create_discounts.rb +0 -0
  96. data/spec/support/rails_app/db/schema.rb +0 -0
  97. data/spec/support/rails_app/db/seeds.rb +0 -0
  98. data/spec/support/rails_app/db/test.sqlite3 +0 -0
  99. data/spec/support/rails_app/public/404.html +0 -0
  100. data/spec/support/rails_app/public/422.html +0 -0
  101. data/spec/support/rails_app/public/500.html +0 -0
  102. data/spec/support/rails_app/public/favicon.ico +0 -0
  103. data/spec/support/rails_app/public/robots.txt +0 -0
  104. data/spec/unit/lazy_crud_spec.rb +0 -0
  105. metadata +28 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f2d4bc24ae30d8d9c2d836d0038bc933c33324f
4
- data.tar.gz: 8bc3051d77b626db265387fae3a1628bdf64a0a4
3
+ metadata.gz: 3ef338f62b22dc0dda807afb5a9d7f8053ec5051
4
+ data.tar.gz: 7b7a9fb0088578d6b3ef10833d903341a4746e3c
5
5
  SHA512:
6
- metadata.gz: fda7d1d74a22b370d0b30014bdc7eb45129032f1fbd0595f92a025f72bc0798b70858307f107f0307f62829e0270b4e72065c578ad39bab44e932233ed90bbce
7
- data.tar.gz: 92661b8c6d655ebe3ba38ce32414e01d3def0ef7bbabbce4ca95f51084f271ba21b6378776215093d471fcbb9c6c7847863dc5ed2b9070588981a5d4b6208066
6
+ metadata.gz: c06d96bb95dd26110a792e19b93dbee39be43316a99d631b8799233049535b636a4d519487af65595041193b12d9336816acd06e1072ca94343e18f214163a5a
7
+ data.tar.gz: 5d76b392f8be9b25563d8a146ccb11b37b34210b755e9284abe91b43dab05c552f7551692fd8d522fdabd5b556804fcdd5651d79953b74e76d304bffce438c8c
data/.codeclimate.yml CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -168,6 +168,3 @@ DEPENDENCIES
168
168
  rspec
169
169
  rspec-rails
170
170
  sqlite3
171
-
172
- BUNDLED WITH
173
- 1.10.3
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -24,11 +24,15 @@ Lazy way to implement common actions in controllers in Rails
24
24
 
25
25
  Gemfile
26
26
 
27
- gem 'lazy_crud'
27
+ ```ruby
28
+ gem 'lazy_crud'
29
+ ```
28
30
 
29
31
  Terminal
30
32
 
31
- gem install lazy_crud
33
+ ```ruby
34
+ gem install lazy_crud
35
+ ```
32
36
 
33
37
  ## Configuration
34
38
 
@@ -38,9 +42,10 @@ Terminal
38
42
  To include all of the basic actions, `create`, `edit`, `destroy`, etc,
39
43
  just add `include LazyCrud` to any controller.
40
44
 
41
- class SomeObjectsController < ApplicationController
42
- include LazyCrud
43
-
45
+ ```ruby
46
+ class SomeObjectsController < ApplicationController
47
+ include LazyCrud
48
+ ```
44
49
 
45
50
  Just make sure the model `SomeObject` exists.
46
51
 
@@ -55,13 +60,17 @@ Event is the parent object and Discount is the resource
55
60
  Note that there must be an `@event` instance variable set.
56
61
  See specs for details.
57
62
 
58
- set_resource_parent Event
63
+ ```ruby
64
+ set_resource_parent Event
65
+ ```
59
66
 
60
67
  However, if you follow standard naming conventions, you can omit the above line
61
68
  and have a controller that looks like this:
62
69
 
63
- Parent::ExamplesController < ApplicationController
64
- include LazyCrud
70
+ ```ruby
71
+ Parent::ExamplesController < ApplicationController
72
+ include LazyCrud
73
+ ```
65
74
 
66
75
  and the `Parent` class would be set as the resource parent.
67
76
 
@@ -73,11 +82,9 @@ If you want to be able to update / create objects, you'll want to
73
82
  specify what parameters are allowed to be set.
74
83
  This uses strong parameters.
75
84
 
76
- set_param_whitelist(:name, :amount)
77
-
78
- # ... other controller stuff
79
- end
80
-
85
+ ```ruby
86
+ set_param_whitelist(:name, :amount)
87
+ ```
81
88
 
82
89
  ### CRUD-hooks
83
90
 
@@ -85,13 +92,17 @@ Sometimes you may want to manually assign attributes to an object before saving,
85
92
 
86
93
  There are two ways to do this:
87
94
 
88
- def before_create
89
- @resource.user = current_user
90
- end
95
+ ```ruby
96
+ def before_create
97
+ @resource.user = current_user
98
+ end
99
+ ```
91
100
 
92
101
  or if you are wanting to have ruby throw an error if you spelled something wrong
93
102
 
94
- before_create ->(resource){ resource.user = current_user }
103
+ ```ruby
104
+ before_create ->(resource){ resource.user = current_user }
105
+ ```
95
106
 
96
107
  the error thrown will be NoMethodError
97
108
 
@@ -103,9 +114,11 @@ Each hook can be called multiple times, and they will be invoked in the order th
103
114
 
104
115
  If you really don't want any default functionality, you can always override
105
116
 
106
- def index
107
- @raffles = @event.raffles.with_deleted
108
- end
117
+ ```ruby
118
+ def index
119
+ @raffles = @event.raffles.with_deleted
120
+ end
121
+ ```
109
122
 
110
123
  ## Contributing
111
124
 
data/Rakefile CHANGED
File without changes
data/lazy_crud.gemspec CHANGED
File without changes
File without changes
@@ -33,7 +33,12 @@ module LazyCrud
33
33
  end
34
34
 
35
35
  if parent_name.present?
36
- set_resource_parent parent_name.constantize
36
+ parent_klass = parent_name.safe_constantize
37
+ if parent_klass
38
+ set_resource_parent parent_klass
39
+ else
40
+ logger.debug "[lazy_crud] #{parent_name} could not be found as a class / module."
41
+ end
37
42
  end
38
43
  end
39
44
 
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module LazyCrud
2
- VERSION = "0.9.8.0"
2
+ VERSION = "0.9.8.1"
3
3
  end
data/lib/lazy_crud.rb CHANGED
File without changes
File without changes
File without changes
@@ -0,0 +1,35 @@
1
+ require 'rails_helper'
2
+
3
+ # this is a nested resource
4
+ describe Event::DiscountsController, type: :controller do
5
+
6
+ before(:each) do
7
+ @user = create(:user)
8
+ @event = create(:event, user: @user)
9
+ end
10
+
11
+ describe '#index' do
12
+ before(:each) do
13
+ @discount = create(:discount, event: @event)
14
+ @nope = create(:discount)
15
+ end
16
+
17
+ it 'sets the collection' do
18
+ get :index, event_id: @event.id
19
+
20
+ discounts = assigns(:discounts)
21
+ expect(discounts).to be_present
22
+ expect(discounts).to include(@discount)
23
+ expect(discounts).to_not include(@nope)
24
+ end
25
+
26
+ it 'returns json' do
27
+ get :index, event_id: @event.id, format: :json
28
+
29
+ expect{
30
+ JSON.parse(response.body)
31
+ }.to_not raise_error
32
+ end
33
+ end
34
+
35
+ end
File without changes
@@ -0,0 +1,35 @@
1
+ require 'rails_helper'
2
+
3
+ # this is a nested resource
4
+ describe HostedEvents::DiscountsController, type: :controller do
5
+
6
+ before(:each) do
7
+ @user = create(:user)
8
+ @event = create(:event, user: @user)
9
+ end
10
+
11
+ describe '#index' do
12
+ before(:each) do
13
+ @discount = create(:discount, event: @event)
14
+ @nope = create(:discount)
15
+ end
16
+
17
+ it 'sets the collection' do
18
+ get :index, hosted_event_id: @event.id
19
+
20
+ discounts = assigns(:discounts)
21
+ expect(discounts).to be_present
22
+ expect(discounts).to include(@discount)
23
+ expect(discounts).to_not include(@nope)
24
+ end
25
+
26
+ it 'returns json' do
27
+ get :index, hosted_event_id: @event.id, format: :json
28
+
29
+ expect{
30
+ JSON.parse(response.body)
31
+ }.to_not raise_error
32
+ end
33
+ end
34
+
35
+ end
File without changes
data/spec/rails_helper.rb CHANGED
File without changes
data/spec/spec_helper.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ class Event::DiscountsController < ApplicationController
2
+ include LazyCrud
3
+
4
+ set_param_whitelist(:name, :amount)
5
+
6
+
7
+ end
@@ -0,0 +1,13 @@
1
+ class HostedEvents::DiscountsController < ApplicationController
2
+ before_action :set_event
3
+ include LazyCrud
4
+
5
+ set_resource_parent Event
6
+ set_param_whitelist(:name, :amount)
7
+
8
+
9
+ def set_event
10
+ @event = Event.find(params[:hosted_event_id])
11
+ end
12
+
13
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,14 +1,20 @@
1
1
  Rails.application.routes.draw do
2
2
  resources :users
3
3
 
4
- resources :events do
5
- resources :discounts do
6
- member do
7
- post :undestroy
8
- end
4
+ resources :discounts do
5
+ member do
6
+ post :undestroy
9
7
  end
10
8
  end
11
9
 
10
+ resources :events do
11
+ resources :discounts, controller: 'events/discounts'
12
+ end
13
+
14
+ resources :hosted_events do
15
+ resources :discounts, controller: 'hosted_events/discounts'
16
+ end
17
+
12
18
 
13
19
  # The priority is based upon order of creation: first created -> highest priority.
14
20
  # See how all your routes lay out with "rake routes".
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_crud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.0
4
+ version: 0.9.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -215,7 +215,9 @@ files:
215
215
  - lib/lazy_crud/version.rb
216
216
  - lib/responders/json_responder.rb
217
217
  - spec/integration/discounts_controller_spec.rb
218
+ - spec/integration/event_discounts_controller_spec.rb
218
219
  - spec/integration/events_controller_spec.rb
220
+ - spec/integration/hosted_events_discount_controller_spec.rb
219
221
  - spec/integration/users_controller_spec.rb
220
222
  - spec/rails_helper.rb
221
223
  - spec/spec_helper.rb
@@ -232,7 +234,9 @@ files:
232
234
  - spec/support/rails_app/app/assets/stylesheets/users.css
233
235
  - spec/support/rails_app/app/controllers/application_controller.rb
234
236
  - spec/support/rails_app/app/controllers/discounts_controller.rb
237
+ - spec/support/rails_app/app/controllers/event/discounts_controller.rb
235
238
  - spec/support/rails_app/app/controllers/events_controller.rb
239
+ - spec/support/rails_app/app/controllers/hosted_events/discounts_controller.rb
236
240
  - spec/support/rails_app/app/controllers/users_controller.rb
237
241
  - spec/support/rails_app/app/helpers/application_helper.rb
238
242
  - spec/support/rails_app/app/helpers/events_helper.rb
@@ -247,10 +251,18 @@ files:
247
251
  - spec/support/rails_app/app/views/discounts/new.html.erb
248
252
  - spec/support/rails_app/app/views/discounts/show.html.erb
249
253
  - spec/support/rails_app/app/views/events/_form.html.erb
254
+ - spec/support/rails_app/app/views/events/discounts/edit.html.erb
255
+ - spec/support/rails_app/app/views/events/discounts/index.html.erb
256
+ - spec/support/rails_app/app/views/events/discounts/new.html.erb
257
+ - spec/support/rails_app/app/views/events/discounts/show.html.erb
250
258
  - spec/support/rails_app/app/views/events/edit.html.erb
251
259
  - spec/support/rails_app/app/views/events/index.html.erb
252
260
  - spec/support/rails_app/app/views/events/new.html.erb
253
261
  - spec/support/rails_app/app/views/events/show.html.erb
262
+ - spec/support/rails_app/app/views/hosted_events/discounts/edit.html.erb
263
+ - spec/support/rails_app/app/views/hosted_events/discounts/index.html.erb
264
+ - spec/support/rails_app/app/views/hosted_events/discounts/new.html.erb
265
+ - spec/support/rails_app/app/views/hosted_events/discounts/show.html.erb
254
266
  - spec/support/rails_app/app/views/layouts/application.html.erb
255
267
  - spec/support/rails_app/app/views/users/_form.html.erb
256
268
  - spec/support/rails_app/app/views/users/edit.html.erb
@@ -313,13 +325,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
325
  version: '0'
314
326
  requirements: []
315
327
  rubyforge_project:
316
- rubygems_version: 2.4.7
328
+ rubygems_version: 2.4.6
317
329
  signing_key:
318
330
  specification_version: 4
319
- summary: LazyCrud-0.9.8.0
331
+ summary: LazyCrud-0.9.8.1
320
332
  test_files:
321
333
  - spec/integration/discounts_controller_spec.rb
334
+ - spec/integration/event_discounts_controller_spec.rb
322
335
  - spec/integration/events_controller_spec.rb
336
+ - spec/integration/hosted_events_discount_controller_spec.rb
323
337
  - spec/integration/users_controller_spec.rb
324
338
  - spec/rails_helper.rb
325
339
  - spec/spec_helper.rb
@@ -336,7 +350,9 @@ test_files:
336
350
  - spec/support/rails_app/app/assets/stylesheets/users.css
337
351
  - spec/support/rails_app/app/controllers/application_controller.rb
338
352
  - spec/support/rails_app/app/controllers/discounts_controller.rb
353
+ - spec/support/rails_app/app/controllers/event/discounts_controller.rb
339
354
  - spec/support/rails_app/app/controllers/events_controller.rb
355
+ - spec/support/rails_app/app/controllers/hosted_events/discounts_controller.rb
340
356
  - spec/support/rails_app/app/controllers/users_controller.rb
341
357
  - spec/support/rails_app/app/helpers/application_helper.rb
342
358
  - spec/support/rails_app/app/helpers/events_helper.rb
@@ -351,10 +367,18 @@ test_files:
351
367
  - spec/support/rails_app/app/views/discounts/new.html.erb
352
368
  - spec/support/rails_app/app/views/discounts/show.html.erb
353
369
  - spec/support/rails_app/app/views/events/_form.html.erb
370
+ - spec/support/rails_app/app/views/events/discounts/edit.html.erb
371
+ - spec/support/rails_app/app/views/events/discounts/index.html.erb
372
+ - spec/support/rails_app/app/views/events/discounts/new.html.erb
373
+ - spec/support/rails_app/app/views/events/discounts/show.html.erb
354
374
  - spec/support/rails_app/app/views/events/edit.html.erb
355
375
  - spec/support/rails_app/app/views/events/index.html.erb
356
376
  - spec/support/rails_app/app/views/events/new.html.erb
357
377
  - spec/support/rails_app/app/views/events/show.html.erb
378
+ - spec/support/rails_app/app/views/hosted_events/discounts/edit.html.erb
379
+ - spec/support/rails_app/app/views/hosted_events/discounts/index.html.erb
380
+ - spec/support/rails_app/app/views/hosted_events/discounts/new.html.erb
381
+ - spec/support/rails_app/app/views/hosted_events/discounts/show.html.erb
358
382
  - spec/support/rails_app/app/views/layouts/application.html.erb
359
383
  - spec/support/rails_app/app/views/users/_form.html.erb
360
384
  - spec/support/rails_app/app/views/users/edit.html.erb