rails-add_ons 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/app/assets/javascripts/rails/add_ons/application/acts-as-list.js.coffee +21 -0
- data/app/assets/javascripts/rails/add_ons/application.js +0 -2
- data/app/components/component/collection_table.rb +26 -2
- data/app/components/component/resource_table.rb +7 -1
- data/app/concerns/component/collection_table/acts_as_list_concern.rb +16 -0
- data/app/concerns/component/collection_table/acts_as_published_concern.rb +10 -0
- data/app/concerns/component/collection_table/batch_actions_concern.rb +12 -0
- data/app/concerns/component/collection_table/boolean_concern.rb +10 -0
- data/app/concerns/component/resource_table/boolean_concern.rb +10 -0
- data/app/concerns/resources_controller/acts_as_list_concern.rb +32 -0
- data/app/concerns/resources_controller/acts_as_published_concern.rb +73 -0
- data/app/concerns/resources_controller/awesome_nested_set_concern.rb +31 -0
- data/app/concerns/resources_controller/batch_actions_concern.rb +16 -0
- data/app/concerns/resources_controller/friendly_id_concern.rb +15 -0
- data/app/concerns/resources_controller/kaminari.rb +13 -11
- data/app/concerns/resources_controller/location_history.rb +31 -26
- data/app/concerns/resources_controller/pagination.rb +13 -11
- data/app/concerns/resources_controller/resource_inflections.rb +13 -11
- data/app/concerns/resources_controller/resources.rb +9 -7
- data/app/concerns/resources_controller/rest_actions.rb +77 -73
- data/app/concerns/resources_controller/rest_resource_urls.rb +25 -23
- data/app/concerns/resources_controller/sorting.rb +22 -14
- data/app/concerns/resources_controller/will_paginate.rb +14 -12
- data/app/concerns/service_controller/rest_actions.rb +15 -0
- data/app/helpers/rails/add_ons/table_helper.rb +10 -0
- data/app/views/component/_collection_table.haml +13 -12
- data/app/views/component/table/body_cells/_acts_as_list.haml +11 -0
- data/app/views/component/table/body_cells/_acts_as_published.haml +9 -0
- data/app/views/component/table/body_cells/_association.haml +5 -1
- data/app/views/component/table/body_cells/_batch_actions.haml +1 -0
- data/app/views/component/table/body_cells/_boolean.haml +4 -0
- data/app/views/component/table/header_cells/_batch_actions.haml +42 -0
- data/config/locales/de.yml +30 -1
- data/config/locales/en.yml +4 -1
- data/lib/generators/rails/add_ons/install_generator.rb +15 -0
- data/lib/generators/rails/add_ons/resources_controller_spec_generator.rb +53 -0
- data/lib/generators/rails/add_ons/templates/initializer.rb +7 -0
- data/lib/generators/rails/add_ons/templates/spec.rb +53 -0
- data/lib/rails/add_ons/configuration.rb +11 -0
- data/lib/rails/add_ons/shoulda/matchers/implement_create_action_matcher.rb +36 -4
- data/lib/rails/add_ons/shoulda/matchers/implement_update_action_matcher.rb +60 -17
- data/lib/rails/add_ons/version.rb +1 -1
- data/lib/rails/add_ons.rb +3 -2
- metadata +23 -2
@@ -15,6 +15,33 @@ module Rails
|
|
15
15
|
# }
|
16
16
|
# end
|
17
17
|
#
|
18
|
+
# The newly created resource is found by calling @resource_class.last.
|
19
|
+
# If you need to change this you can call #finding_created_resource_with.
|
20
|
+
#
|
21
|
+
# Example:
|
22
|
+
#
|
23
|
+
# RSpec.describe '/posts', type: :feature do
|
24
|
+
# it {
|
25
|
+
# expect(subject).to implement_create_action(self)
|
26
|
+
# .for(resource_class)
|
27
|
+
# .within_form('#new_user') {
|
28
|
+
# # fill the needed form inputs via capybara here
|
29
|
+
# #
|
30
|
+
# # Example:
|
31
|
+
# #
|
32
|
+
# # select 'de', from: 'slider[locale]'
|
33
|
+
# # fill_in 'slider[name]', with: 'My first slider'
|
34
|
+
# # check 'slider[auto_start]'
|
35
|
+
# # fill_in 'slider[interval]', with: '3'
|
36
|
+
# fill_in 'user[email]', with: 'jane.doe@local.domain'
|
37
|
+
# fill_in 'user[password]', with: 'password'
|
38
|
+
# fill_in 'user[password_confirmation]', with: 'password'
|
39
|
+
# }
|
40
|
+
# .finding_created_resource_with{ Ecm::UserArea::User.order(created_at: :desc).first }
|
41
|
+
# .increasing{ Ecm::UserArea::User.count }.by(1)
|
42
|
+
# }
|
43
|
+
# end
|
44
|
+
#
|
18
45
|
def implement_create_action(spec)
|
19
46
|
ImplementCreateActionMatcher.new(spec)
|
20
47
|
end
|
@@ -54,6 +81,11 @@ module Rails
|
|
54
81
|
self
|
55
82
|
end
|
56
83
|
|
84
|
+
def finding_created_resource_with(&block)
|
85
|
+
@created_resource_finder_block = block
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
57
89
|
def matches?(base_path)
|
58
90
|
@base_path = base_path
|
59
91
|
@new_path = "#{@base_path}/new"
|
@@ -67,11 +99,11 @@ module Rails
|
|
67
99
|
end
|
68
100
|
@after_count = @block.call(@resource_class)
|
69
101
|
|
70
|
-
has_correct_status_code &&
|
102
|
+
has_correct_status_code && has_increased_resource_count && has_correct_current_path
|
71
103
|
end
|
72
104
|
|
73
105
|
def created_resource
|
74
|
-
@created_resource ||= @resource_class.
|
106
|
+
@created_resource ||= @created_resource_finder_block.present? ? @created_resource_finder_block.call : @resource_class.last
|
75
107
|
end
|
76
108
|
|
77
109
|
def expected_path
|
@@ -88,10 +120,10 @@ module Rails
|
|
88
120
|
end
|
89
121
|
|
90
122
|
def has_increased_resource_count
|
91
|
-
if (@
|
123
|
+
if (@after_count - @before_count) == @expected_increase
|
92
124
|
true
|
93
125
|
else
|
94
|
-
@error = "Did not increase by expected [#{@expected_increase}] but by [#{@
|
126
|
+
@error = "Did not increase by expected [#{@expected_increase}] but by [#{@after_count - @before_count}]"
|
95
127
|
false
|
96
128
|
end
|
97
129
|
end
|
@@ -2,7 +2,7 @@ module Rails
|
|
2
2
|
module AddOns
|
3
3
|
module Shoulda
|
4
4
|
module Matchers
|
5
|
-
# Example:
|
5
|
+
# Example checking for changed resource attributes:
|
6
6
|
#
|
7
7
|
# RSpec.describe '/posts', type: :feature do
|
8
8
|
# let(:post) { create(:post) }
|
@@ -13,12 +13,29 @@ module Rails
|
|
13
13
|
# fill_in 'post[title]', with: 'New title'
|
14
14
|
# fill_in 'post[body]', with: 'New body'
|
15
15
|
# }
|
16
|
-
# .updating
|
16
|
+
# .updating
|
17
17
|
# .from(post.attributes)
|
18
18
|
# .to({ 'title' => 'New title', 'body' => 'New body' })
|
19
19
|
# }
|
20
20
|
# end
|
21
21
|
#
|
22
|
+
# Example checking for changed state:
|
23
|
+
#
|
24
|
+
# RSpec.describe '/posts', type: :feature do
|
25
|
+
# let(:post) { create(:post) }
|
26
|
+
# it {
|
27
|
+
# expect(subject).to implement_update_action(self)
|
28
|
+
# .for(post)
|
29
|
+
# .within_form('.edit_post') {
|
30
|
+
# fill_in 'post[title]', with: 'New title'
|
31
|
+
# fill_in 'post[body]', with: 'New body'
|
32
|
+
# }
|
33
|
+
# .updating{ |resource| resource.updated_by }
|
34
|
+
# .from(nil)
|
35
|
+
# .to(User.current)
|
36
|
+
# }
|
37
|
+
# end
|
38
|
+
#
|
22
39
|
def implement_update_action(spec)
|
23
40
|
ImplementUpdateActionMatcher.new(spec)
|
24
41
|
end
|
@@ -36,13 +53,13 @@ module Rails
|
|
36
53
|
self
|
37
54
|
end
|
38
55
|
|
39
|
-
def from(
|
40
|
-
@
|
56
|
+
def from(value)
|
57
|
+
@from = value
|
41
58
|
self
|
42
59
|
end
|
43
60
|
|
44
|
-
def to(
|
45
|
-
@
|
61
|
+
def to(value)
|
62
|
+
@to = value
|
46
63
|
self
|
47
64
|
end
|
48
65
|
|
@@ -54,7 +71,7 @@ module Rails
|
|
54
71
|
end
|
55
72
|
|
56
73
|
def updating(&block)
|
57
|
-
@
|
74
|
+
@updating_block = block if block_given?
|
58
75
|
self
|
59
76
|
end
|
60
77
|
|
@@ -102,22 +119,48 @@ module Rails
|
|
102
119
|
end
|
103
120
|
|
104
121
|
def has_correct_attributes_before
|
105
|
-
|
106
|
-
if @
|
107
|
-
|
122
|
+
expected = @from
|
123
|
+
if @updating_block.present?
|
124
|
+
given = @updating_block.call(@resource)
|
125
|
+
|
126
|
+
if given == expected
|
127
|
+
return true
|
128
|
+
else
|
129
|
+
@error = "Before update state [#{given.inspect}] did not match expected [#{expected.inspect}]"
|
130
|
+
return false
|
131
|
+
end
|
108
132
|
else
|
109
|
-
|
110
|
-
|
133
|
+
given = @resource.attributes.with_indifferent_access.slice(*@expected_before_attributes.keys)
|
134
|
+
|
135
|
+
if given == expected
|
136
|
+
true
|
137
|
+
else
|
138
|
+
@error = "Attributes before update [#{given}] did not match expected attributes [#{@expected_before_attributes}]"
|
139
|
+
false
|
140
|
+
end
|
111
141
|
end
|
112
142
|
end
|
113
143
|
|
114
144
|
def has_correct_attributes_after
|
115
|
-
|
116
|
-
if @
|
117
|
-
|
145
|
+
expected = @to
|
146
|
+
if @updating_block.present?
|
147
|
+
given = @updating_block.call(@resource)
|
148
|
+
|
149
|
+
if given == expected
|
150
|
+
return true
|
151
|
+
else
|
152
|
+
@error = "After update state [#{given.inspect}] did not match expected [#{expected.inspect}]"
|
153
|
+
return false
|
154
|
+
end
|
118
155
|
else
|
119
|
-
|
120
|
-
|
156
|
+
given = @resource.attributes.with_indifferent_access.slice(*@to.keys)
|
157
|
+
|
158
|
+
if given == expected
|
159
|
+
true
|
160
|
+
else
|
161
|
+
@error = "Attributes after update [#{given}] did not match expected attributes [#{@expected_before_attributes}]"
|
162
|
+
false
|
163
|
+
end
|
121
164
|
end
|
122
165
|
end
|
123
166
|
|
data/lib/rails/add_ons.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-add_ons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- Rakefile
|
177
177
|
- app/assets/config/rails_add_ons_manifest.js
|
178
178
|
- app/assets/javascripts/rails/add_ons/application.js
|
179
|
+
- app/assets/javascripts/rails/add_ons/application/acts-as-list.js.coffee
|
179
180
|
- app/assets/javascripts/rails/add_ons/application/widgets.js.coffee
|
180
181
|
- app/assets/javascripts/rails_add_ons.js
|
181
182
|
- app/assets/stylesheets/rails/add_ons/application.scss
|
@@ -190,8 +191,18 @@ files:
|
|
190
191
|
- app/components/component/collection_table.rb
|
191
192
|
- app/components/component/resource_table.rb
|
192
193
|
- app/concerns/api_controller_concerns/exception_handling.rb
|
194
|
+
- app/concerns/component/collection_table/acts_as_list_concern.rb
|
195
|
+
- app/concerns/component/collection_table/acts_as_published_concern.rb
|
193
196
|
- app/concerns/component/collection_table/awesome_nested_set_concern.rb
|
197
|
+
- app/concerns/component/collection_table/batch_actions_concern.rb
|
198
|
+
- app/concerns/component/collection_table/boolean_concern.rb
|
199
|
+
- app/concerns/component/resource_table/boolean_concern.rb
|
194
200
|
- app/concerns/controller/query_conditions.rb
|
201
|
+
- app/concerns/resources_controller/acts_as_list_concern.rb
|
202
|
+
- app/concerns/resources_controller/acts_as_published_concern.rb
|
203
|
+
- app/concerns/resources_controller/awesome_nested_set_concern.rb
|
204
|
+
- app/concerns/resources_controller/batch_actions_concern.rb
|
205
|
+
- app/concerns/resources_controller/friendly_id_concern.rb
|
195
206
|
- app/concerns/resources_controller/kaminari.rb
|
196
207
|
- app/concerns/resources_controller/location_history.rb
|
197
208
|
- app/concerns/resources_controller/pagination.rb
|
@@ -221,10 +232,15 @@ files:
|
|
221
232
|
- app/services/rails/add_ons/service/result/base.rb
|
222
233
|
- app/views/component/_collection_table.haml
|
223
234
|
- app/views/component/_resource_table.haml
|
235
|
+
- app/views/component/table/body_cells/_acts_as_list.haml
|
236
|
+
- app/views/component/table/body_cells/_acts_as_published.haml
|
224
237
|
- app/views/component/table/body_cells/_association.haml
|
225
238
|
- app/views/component/table/body_cells/_awesome_nested_set.haml
|
239
|
+
- app/views/component/table/body_cells/_batch_actions.haml
|
240
|
+
- app/views/component/table/body_cells/_boolean.haml
|
226
241
|
- app/views/component/table/body_cells/_default.haml
|
227
242
|
- app/views/component/table/body_cells/_timestamp.haml
|
243
|
+
- app/views/component/table/header_cells/_batch_actions.haml
|
228
244
|
- app/views/frontend/_after_body.haml
|
229
245
|
- app/views/frontend/_after_head.haml
|
230
246
|
- app/views/frontend/_before_body.haml
|
@@ -262,8 +278,13 @@ files:
|
|
262
278
|
- config/locales/en.yml
|
263
279
|
- config/routes.rb
|
264
280
|
- lib/active_model/model.rb
|
281
|
+
- lib/generators/rails/add_ons/install_generator.rb
|
282
|
+
- lib/generators/rails/add_ons/resources_controller_spec_generator.rb
|
283
|
+
- lib/generators/rails/add_ons/templates/initializer.rb
|
284
|
+
- lib/generators/rails/add_ons/templates/spec.rb
|
265
285
|
- lib/rails-add_ons.rb
|
266
286
|
- lib/rails/add_ons.rb
|
287
|
+
- lib/rails/add_ons/configuration.rb
|
267
288
|
- lib/rails/add_ons/engine.rb
|
268
289
|
- lib/rails/add_ons/shoulda/matchers.rb
|
269
290
|
- lib/rails/add_ons/shoulda/matchers/implement_create_action_matcher.rb
|