dry_crud 2.1.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +5 -13
  2. data/README.rdoc +1 -2
  3. data/VERSION +1 -1
  4. data/app/controllers/crud_controller.rb +96 -61
  5. data/app/controllers/dry_crud/generic_model.rb +1 -5
  6. data/app/controllers/dry_crud/rememberable.rb +1 -1
  7. data/app/controllers/dry_crud/render_callbacks.rb +2 -4
  8. data/app/controllers/list_controller.rb +4 -5
  9. data/app/helpers/dry_crud/form/builder.rb +4 -30
  10. data/app/helpers/format_helper.rb +2 -0
  11. data/app/helpers/utility_helper.rb +2 -3
  12. data/app/views/crud/show.json.jbuilder +1 -0
  13. data/app/views/layouts/_flash.html.erb +1 -1
  14. data/app/views/layouts/_flash.html.haml +1 -1
  15. data/app/views/list/index.json.jbuilder +4 -0
  16. data/config/locales/crud.de.yml +1 -1
  17. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +141 -139
  18. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +47 -48
  19. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +6 -6
  20. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +66 -66
  21. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +62 -61
  22. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +13 -13
  23. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +42 -38
  24. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +22 -22
  25. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +72 -72
  26. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +54 -45
  27. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +8 -11
  28. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +1 -6
  29. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +47 -46
  30. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +1 -1
  31. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +9 -3
  32. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +2 -2
  33. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +1 -1
  34. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +0 -4
  35. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +5 -10
  36. metadata +15 -18
  37. data/app/controllers/dry_crud/responder.rb +0 -34
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MWE4YzQzMjYxYmZlZWExOWUzZjczNDE2OWRlMTQwZDM4NDU5OTNlMg==
5
- data.tar.gz: !binary |-
6
- OTUzZWFjODA5NzRlZTVlMGQzYzZiOTMzNGRkNjIxNDM4OWM0OTZlMw==
2
+ SHA1:
3
+ metadata.gz: 664cf77c042838728de2d0abb74525808c496448
4
+ data.tar.gz: e12c82079d72d2f414cef3181d2fcd14e9f72552
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MWY5NDJlYmQ2NjE1OGJlZjEzMGRlZmE1YmUzM2EzZDQ4Nzk3YjJhYzVhZWI5
10
- OGQyNzI5OGJmMDgwYjU1N2Y3OTk5MjA2ZTgyNTU3OGI1NDhjODViNmJjZDVm
11
- YWIyODY4YzIzODIxNDk2ZGQ4M2E2ODE4ZDQwOWQ2NmFjYTczYzE=
12
- data.tar.gz: !binary |-
13
- ODc3YTliNjQ5YzZhMGQwMjIxMTMwYzBlMDMzNDhjM2I5MDg0NzEwNGY0YTk0
14
- NGRjN2Q2MWVkZjBhZjQzMmYzMTJhMDYyM2MwYzlkZGZmZTk0ZjY0NzVjMTE0
15
- OTVmODcyNDNkNzUwNDJlNmIyN2E4NDFlZjhkZjIzZTY3NTRjYzM=
6
+ metadata.gz: fb4bd2d805c8bc9a0dfa4a3eb3cf25758d70abcde034b9380d6e181bb1a8918420be98c326d036926d30c92b56fe0a7d02d5232e30a0a72b704cc02d2c9fa660
7
+ data.tar.gz: 5851c097e6904e68f7abaec88d5c0bec6c651de07e482737f667dd7832f976a9bb5b390900669910e945e5fc33afae27359735f1ae3c2420f7f0309902135821
@@ -33,7 +33,7 @@ To integrate dry_crud into your code, only a few additions are required:
33
33
  * Optionally define a +list+ scope in your models to be used in the +index+ action.
34
34
  * Optionally define a +options_list+ scope in your models to be used in select dropdowns.
35
35
 
36
- Version 2.0 and higher are compatible with Rails 4 and Rails 3.2. dry_crud is tested with Ruby 1.9.3, 2.0.0 and JRuby. If you are using Ruby 1.8.7, please refer to version 1.7.0.
36
+ From version 3.0, only the latest released Rails version will be supported, which currently is 4.2. Version 2.0 and higher are compatible with Rails 4 and Rails 3.2. dry_crud is tested with Ruby 1.9.3, 2.1.5 and JRuby. If you are using Ruby 1.8.7, please refer to version 1.7.0.
37
37
 
38
38
 
39
39
  == Background
@@ -392,4 +392,3 @@ spec/support/crud_test_model.rb:: A dummy model to run CRUD tests against.
392
392
  spec/controllers/crud_test_models_controller_spec.rb:: Controller specs to test the basic CrudController functionality.
393
393
 
394
394
  spec/helpers/*_spec.rb:: The specs for all the helpers included in dry_crud and a great base to test your adaptions of the CRUD code.
395
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 3.0.0
@@ -11,11 +11,7 @@
11
11
  # action procedures without overriding the entire method.
12
12
  class CrudController < ListController
13
13
 
14
- self.responder = DryCrud::Responder
15
-
16
- if Rails.version >= '4.0'
17
- class_attribute :permitted_attrs
18
- end
14
+ class_attribute :permitted_attrs
19
15
 
20
16
  # Defines before and after callback hooks for create, update, save and
21
17
  # destroy actions.
@@ -28,79 +24,114 @@ class CrudController < ListController
28
24
 
29
25
  hide_action :run_callbacks
30
26
 
31
- after_save :set_success_notice
32
- after_destroy :set_success_notice
27
+ before_action :entry, only: [:show, :new, :edit, :update, :destroy]
33
28
 
34
29
  helper_method :entry, :full_entry_label
35
30
 
36
31
  ############## ACTIONS ############################################
37
32
 
38
- # Show one entry of this model.
39
33
  # GET /entries/1
40
34
  # GET /entries/1.json
41
- def show(&block)
42
- respond_with(entry, &block)
35
+ #
36
+ # Show one entry of this model.
37
+ def show
43
38
  end
44
39
 
45
- # Display a form to create a new entry of this model.
46
40
  # GET /entries/new
47
41
  # GET /entries/new.json
48
- def new(&block)
42
+ #
43
+ # Display a form to create a new entry of this model.
44
+ def new
49
45
  assign_attributes if params[model_identifier]
50
- respond_with(entry, &block)
51
46
  end
52
47
 
48
+ # POST /entries
49
+ # POST /entries.json
50
+ #
53
51
  # Create a new entry of this model from the passed params.
54
52
  # There are before and after create callbacks to hook into the action.
55
- # To customize the response, you may overwrite this action and call
56
- # super with a block that gets the format parameter.
53
+ #
54
+ # To customize the response for certain formats, you may overwrite
55
+ # this action and call super with a block that gets the format and
56
+ # success parameters. Calling a format action (e.g. format.html)
57
+ # in the given block will take precedence over the one defined here.
58
+ #
57
59
  # Specify a :location option if you wish to do a custom redirect.
58
- # POST /entries
59
- # POST /entries.json
60
60
  def create(options = {}, &block)
61
61
  assign_attributes
62
62
  created = with_callbacks(:create, :save) { entry.save }
63
- respond_options = options.reverse_merge(success: created)
64
- respond_with(entry, respond_options, &block)
63
+
64
+ respond_to do |format|
65
+ block.call(format, created) if block_given?
66
+ if created
67
+ format.html { redirect_on_success(options) }
68
+ format.json { render :show, status: :created, location: show_path }
69
+ else
70
+ format.html { render :new }
71
+ format.json { render json: entry.errors, status: :unprocessable_entity }
72
+ end
73
+ end
65
74
  end
66
75
 
67
- # Display a form to edit an exisiting entry of this model.
68
76
  # GET /entries/1/edit
69
- def edit(&block)
70
- respond_with(entry, &block)
77
+ #
78
+ # Display a form to edit an exisiting entry of this model.
79
+ def edit
71
80
  end
72
81
 
82
+ # PUT /entries/1
83
+ # PUT /entries/1.json
84
+ #
73
85
  # Update an existing entry of this model from the passed params.
74
86
  # There are before and after update callbacks to hook into the action.
75
- # To customize the response, you may overwrite this action and call
76
- # super with a block that gets the format parameter.
87
+ #
88
+ # To customize the response for certain formats, you may overwrite
89
+ # this action and call super with a block that gets the format and
90
+ # success parameters. Calling a format action (e.g. format.html)
91
+ # in the given block will take precedence over the one defined here.
92
+ #
77
93
  # Specify a :location option if you wish to do a custom redirect.
78
- # PUT /entries/1
79
- # PUT /entries/1.json
80
94
  def update(options = {}, &block)
81
95
  assign_attributes
82
96
  updated = with_callbacks(:update, :save) { entry.save }
83
- respond_options = options.reverse_merge(success: updated)
84
- respond_with(entry, respond_options, &block)
97
+
98
+ respond_to do |format|
99
+ block.call(format, updated) if block_given?
100
+ if updated
101
+ format.html { redirect_on_success(options) }
102
+ format.json { render :show, status: :ok, location: show_path }
103
+ else
104
+ format.html { render :edit }
105
+ format.json { render json: entry.errors, status: :unprocessable_entity }
106
+ end
107
+ end
85
108
  end
86
109
 
110
+ # DELETE /entries/1
111
+ # DELETE /entries/1.json
112
+ #
87
113
  # Destroy an existing entry of this model.
88
114
  # There are before and after destroy callbacks to hook into the action.
89
- # To customize the response, you may overwrite this action and call
90
- # super with a block that gets success and format parameters.
115
+ #
116
+ # To customize the response for certain formats, you may overwrite
117
+ # this action and call super with a block that gets format and
118
+ # success parameters. Calling a format action (e.g. format.html)
119
+ # in the given block will take precedence over the one defined here.
120
+ #
91
121
  # Specify a :location option if you wish to do a custom redirect.
92
- # DELETE /entries/1
93
- # DELETE /entries/1.json
94
122
  def destroy(options = {}, &block)
95
123
  destroyed = run_callbacks(:destroy) { entry.destroy }
96
- unless destroyed
97
- set_failure_notice
98
- location = request.env['HTTP_REFERER'].presence
124
+
125
+ respond_to do |format|
126
+ block.call(format, destroyed) if block_given?
127
+ if destroyed
128
+ format.html { redirect_on_success(options) }
129
+ format.json { head :no_content }
130
+ else
131
+ format.html { redirect_on_failure(options) }
132
+ format.json { render json: entry.errors, status: :unprocessable_entity }
133
+ end
99
134
  end
100
- location ||= index_url
101
- respond_options = options.reverse_merge(success: destroyed,
102
- location: location)
103
- respond_with(entry, respond_options, &block)
104
135
  end
105
136
 
106
137
  private
@@ -129,35 +160,34 @@ class CrudController < ListController
129
160
 
130
161
  # The form params for this model.
131
162
  def model_params
132
- if Rails.version < '4.0'
133
- params[model_identifier]
134
- else
135
- params.require(model_identifier).permit(permitted_attrs)
136
- end
163
+ params.require(model_identifier).permit(permitted_attrs)
137
164
  end
138
165
 
139
- # Url of the index page to return to.
140
- def index_url
141
- polymorphic_url(path_args(model_class), returning: true)
166
+ # Path of the index page to return to.
167
+ def index_path
168
+ polymorphic_path(path_args(model_class), returning: true)
142
169
  end
143
170
 
144
- # A label for the current entry, including the model name.
145
- def full_entry_label
146
- "#{models_label(false)} <i>#{ERB::Util.h(entry)}</i>".html_safe
171
+ # Path of the show page.
172
+ def show_path
173
+ path_args(entry)
147
174
  end
148
175
 
149
- # Set a success flash notice when we got a HTML request.
150
- def set_success_notice
151
- if request.format == :html
152
- flash[:notice] ||= flash_message(:success)
153
- end
176
+ # Perform a redirect after a successfull operation and set a flash notice.
177
+ def redirect_on_success(options = {})
178
+ location = options[:location] ||
179
+ (entry.destroyed? ? index_path : show_path)
180
+ flash[:notice] ||= flash_message(:success)
181
+ redirect_to location
154
182
  end
155
183
 
156
- # Set a failure flash notice when we got a HTML request.
157
- def set_failure_notice
158
- if request.format == :html
159
- flash[:alert] ||= error_messages.presence || flash_message(:failure)
160
- end
184
+ # Perform a redirect after a failed operation and set a flash alert.
185
+ def redirect_on_failure(options = {})
186
+ location = options[:location] ||
187
+ request.env['HTTP_REFERER'].presence ||
188
+ index_path
189
+ flash[:alert] ||= error_messages.presence || flash_message(:failure)
190
+ redirect_to location
161
191
  end
162
192
 
163
193
  # Get an I18n flash message.
@@ -169,7 +199,12 @@ class CrudController < ListController
169
199
  :"#{controller_name}.#{scope}",
170
200
  :"crud.#{scope}_html",
171
201
  :"crud.#{scope}"]
172
- I18n.t(keys.shift, model: full_entry_label, default: keys).html_safe
202
+ I18n.t(keys.shift, model: full_entry_label, default: keys)
203
+ end
204
+
205
+ # A label for the current entry, including the model name.
206
+ def full_entry_label
207
+ "#{models_label(false)} <i>#{ERB::Util.h(entry)}</i>".html_safe
173
208
  end
174
209
 
175
210
  # Html safe error messages of the current entry.
@@ -24,11 +24,7 @@ module DryCrud
24
24
  # This is mainly used for nested models to provide the
25
25
  # required context.
26
26
  def model_scope
27
- if Rails.version < '4.0'
28
- model_class.scoped
29
- else
30
- model_class.all
31
- end
27
+ model_class.all
32
28
  end
33
29
 
34
30
  # The path arguments to link to the given model entry.
@@ -16,7 +16,7 @@ module DryCrud
16
16
 
17
17
  included do
18
18
  class_attribute :remember_params
19
- self.remember_params = [:q, :sort, :sort_dir, :page]
19
+ self.remember_params = %w(q sort sort_dir page)
20
20
 
21
21
  before_filter :handle_remember_params, only: [:index]
22
22
  end
@@ -37,10 +37,8 @@ module DryCrud
37
37
  # Defines before callbacks for the render actions.
38
38
  def define_render_callbacks(*actions)
39
39
  args = actions.map { |a| :"render_#{a}" }
40
- # Rails 4.1 terminator:
41
- # ->(ctrl, result) { result == false || ctrl.performed? }
42
- args << { only: :before,
43
- terminator: 'result == false || performed?' }
40
+ terminator = ->(ctrl, result) { result == false || ctrl.performed? }
41
+ args << { only: :before, terminator: terminator }
44
42
  define_model_callbacks(*args)
45
43
  end
46
44
  end
@@ -15,19 +15,18 @@ class ListController < ApplicationController
15
15
  include DryCrud::Rememberable
16
16
  include DryCrud::RenderCallbacks
17
17
 
18
- respond_to :html, :json
19
-
20
18
  define_render_callbacks :index
21
19
 
22
20
  helper_method :entries
23
21
 
24
22
  ############## ACTIONS ############################################
25
23
 
26
- # List all entries of this model.
27
24
  # GET /entries
28
25
  # GET /entries.json
29
- def index(&block)
30
- respond_with(entries, &block)
26
+ #
27
+ # List all entries of this model.
28
+ def index
29
+ entries
31
30
  end
32
31
 
33
32
  private
@@ -83,7 +83,7 @@ module DryCrud
83
83
 
84
84
  # Add form-control class to all input fields.
85
85
  %w(text_field password_field email_field text_area
86
- number_fielc date_field time_field datetime_field).each do |method|
86
+ number_field date_field time_field datetime_field).each do |method|
87
87
  define_method(method) do |attr, html_options = {}|
88
88
  add_css_class(html_options, 'form-control')
89
89
  super(attr, html_options)
@@ -101,27 +101,6 @@ module DryCrud
101
101
  alias_method :float_field, :number_field
102
102
  alias_method :decimal_field, :number_field
103
103
 
104
- if Rails.version < '4.0'
105
- # Render a field to select a date. You might want to customize this.
106
- def date_field(attr, html_options = {})
107
- html_options[:type] = 'date'
108
- text_field(attr, html_options)
109
- end
110
-
111
- # Render a field to enter a time. You might want to customize this.
112
- def time_field(attr, html_options = {})
113
- html_options[:type] = 'time'
114
- text_field(attr, html_options)
115
- end
116
-
117
- # Render a field to enter a date and time.
118
- # You might want to customize this.
119
- def datetime_field(attr, html_options = {})
120
- html_options[:type] = 'datetime'
121
- text_field(attr, html_options)
122
- end
123
- end
124
-
125
104
  # Render a select element for a :belongs_to association defined by attr.
126
105
  # Use additional html_options for the select element.
127
106
  # To pass a custom element list, specify the list with the :list key or
@@ -266,8 +245,8 @@ module DryCrud
266
245
  end
267
246
 
268
247
  # Overriden to fullfill contract with method_missing 'labeled_' methods.
269
- def respond_to?(name)
270
- labeled_field_method?(name).present? || super(name)
248
+ def respond_to?(name, include_private = false)
249
+ labeled_field_method?(name).present? || super(name, include_private)
271
250
  end
272
251
 
273
252
  private
@@ -309,12 +288,7 @@ module DryCrud
309
288
  # Automatically load the entries for the given association.
310
289
  def load_association_entries(assoc)
311
290
  klass = assoc.klass
312
- list = if Rails.version >= '4.0'
313
- klass.all.merge(assoc.scope)
314
- else
315
- klass.where(assoc.options[:conditions])
316
- .order(assoc.options[:order])
317
- end
291
+ list = klass.all.merge(assoc.scope)
318
292
  # Use special scopes if they are defined
319
293
  if klass.respond_to?(:options_list)
320
294
  list.options_list
@@ -15,6 +15,8 @@ module FormatHelper
15
15
  when Float, BigDecimal then
16
16
  number_with_precision(value, precision: t('number.format.precision'),
17
17
  delimiter: t('number.format.delimiter'))
18
+ when Fixnum then
19
+ number_with_delimiter(value, delimiter: t('number.format.delimiter'))
18
20
  when Date then l(value)
19
21
  when Time then "#{l(value.to_date)} #{l(value, format: :time)}"
20
22
  when true then t('global.yes')
@@ -50,9 +50,8 @@ module UtilityHelper
50
50
 
51
51
  # Returns an ActiveRecord column property for the passed attr or nil
52
52
  def column_property(obj, attr, property)
53
- if obj.respond_to?(:column_for_attribute)
54
- column = obj.column_for_attribute(attr)
55
- column.try(property)
53
+ if obj.respond_to?(:column_for_attribute) && obj.has_attribute?(attr)
54
+ obj.column_for_attribute(attr).send(property)
56
55
  end
57
56
  end
58
57
 
@@ -0,0 +1 @@
1
+ json.extract! entry, :id, *default_crud_attrs
@@ -1,5 +1,5 @@
1
1
  <% if flash[level].present? %>
2
2
  <div class="alert alert-<%= flash_class(level) %>">
3
- <%= flash[level] %>
3
+ <%= flash[level].html_safe %>
4
4
  </div>
5
5
  <% end %>
@@ -1,2 +1,2 @@
1
1
  - if flash[level].present?
2
- %div{class: "alert alert-#{flash_class(level)}"}= flash[level]
2
+ %div{class: "alert alert-#{flash_class(level)}"}= flash[level].html_safe
@@ -0,0 +1,4 @@
1
+ json.array!(entries) do |entry|
2
+ json.extract! entry, :id, *default_crud_attrs
3
+ json.url polymorphic_url(path_args(entry), format: :json)
4
+ end
@@ -1,4 +1,4 @@
1
- # Translations of all crud strings.
1
+ # Translations of all crud strings.
2
2
  # See also I18nHelper#translate_inheritable and #translate_association.
3
3
 
4
4
  de:
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require 'spec_helper'
2
+ require 'rails_helper'
3
3
 
4
4
  # Tests all actions of the CrudController based on a dummy model
5
5
  # (CrudTestModel). This is useful to test the general behavior
@@ -43,16 +43,16 @@ describe CrudTestModelsController do
43
43
  end
44
44
 
45
45
  describe 'setup' do
46
- it 'model count should be correct' do
47
- CrudTestModel.count.should == 6
46
+ it 'model count is correct' do
47
+ expect(CrudTestModel.count).to eq(6)
48
48
  end
49
49
 
50
50
  it 'has models_label' do
51
- controller.models_label.should == 'Crud Test Models'
51
+ expect(controller.models_label).to eq('Crud Test Models')
52
52
  end
53
53
 
54
54
  it 'has models_label singular' do
55
- controller.models_label(false).should == 'Crud Test Model'
55
+ expect(controller.models_label(false)).to eq('Crud Test Model')
56
56
  end
57
57
  end
58
58
 
@@ -60,16 +60,16 @@ describe CrudTestModelsController do
60
60
  context '.html', format: :html do
61
61
  context 'plain', combine: 'ihp' do
62
62
  it 'contains all entries' do
63
- entries.size.should == 6
63
+ expect(entries.size).to eq(6)
64
64
  end
65
65
 
66
- it 'session should have empty list_params' do
67
- session[:list_params].should == Hash.new
66
+ it 'session has empty list_params' do
67
+ expect(session[:list_params]).to eq(Hash.new)
68
68
  end
69
69
 
70
70
  it 'provides entries helper method' do
71
- should render_template('index')
72
- entries.should be(controller.send(:entries))
71
+ is_expected.to render_template('index')
72
+ expect(entries).to be(controller.send(:entries))
73
73
  end
74
74
  end
75
75
 
@@ -77,28 +77,28 @@ describe CrudTestModelsController do
77
77
  let(:params) { { q: search_value } }
78
78
 
79
79
  context 'regular', combine: 'ihse' do
80
- it 'entries should only contain test_entry' do
81
- entries.should == [test_entry]
80
+ it 'entries only contain test_entry' do
81
+ expect(entries).to eq([test_entry])
82
82
  end
83
83
 
84
- it 'session should have query list param' do
85
- session[:list_params]['/crud_test_models.html'].should ==
86
- { q: 'AAAA' }
84
+ it 'session has query list param' do
85
+ expect(session[:list_params]['/crud_test_models.html'])
86
+ .to eq('q' => 'AAAA')
87
87
  end
88
88
  end
89
89
 
90
90
  context 'with custom options', combine: 'ihsec' do
91
91
  let(:params) { { q: 'DDD', filter: true } }
92
92
 
93
- it_should_respond
93
+ it_is_expected_to_respond
94
94
 
95
- it 'entries should have one item' do
96
- entries.should == [CrudTestModel.find_by_name('BBBBB')]
95
+ it 'entries have one item' do
96
+ expect(entries).to eq([CrudTestModel.find_by_name('BBBBB')])
97
97
  end
98
98
 
99
- it 'session should have query list param' do
100
- session[:list_params]['/crud_test_models.html'].should ==
101
- { q: 'DDD' }
99
+ it 'session has query list param' do
100
+ expect(session[:list_params]['/crud_test_models.html'])
101
+ .to eq('q' => 'DDD')
102
102
  end
103
103
  end
104
104
  end
@@ -107,24 +107,24 @@ describe CrudTestModelsController do
107
107
  context 'for given column', combine: 'ihsog' do
108
108
  let(:params) { { sort: 'children', sort_dir: 'asc' } }
109
109
 
110
- it_should_respond
110
+ it_is_expected_to_respond
111
111
 
112
- it 'entries should be in correct order' do
113
- entries.should == CrudTestModel.all.sort_by(&:children)
112
+ it 'entries are in correct order' do
113
+ expect(entries).to eq(CrudTestModel.all.sort_by(&:children))
114
114
  end
115
115
 
116
- it 'session should have sort list param' do
117
- session[:list_params]['/crud_test_models.html'].should ==
118
- { sort: 'children', sort_dir: 'asc' }
116
+ it 'session has sort list param' do
117
+ expect(session[:list_params]['/crud_test_models.html']).to eq(
118
+ 'sort' => 'children', 'sort_dir' => 'asc')
119
119
  end
120
120
  end
121
121
 
122
122
  context 'for virtual column', combine: 'ihsov' do
123
123
  let(:params) { { sort: 'chatty', sort_dir: 'desc' } }
124
124
 
125
- it_should_respond
125
+ it_is_expected_to_respond
126
126
 
127
- it 'entries should be in correct order' do
127
+ it 'entries are in correct order' do
128
128
  names = entries.map(&:name)
129
129
  assert names.index('BBBBB') < names.index('AAAAA')
130
130
  assert names.index('BBBBB') < names.index('DDDDD')
@@ -134,9 +134,9 @@ describe CrudTestModelsController do
134
134
  assert names.index('DDDDD') < names.index('CCCCC')
135
135
  end
136
136
 
137
- it 'session should have sort list param' do
138
- session[:list_params]['/crud_test_models.html'].should ==
139
- { sort: 'chatty', sort_dir: 'desc' }
137
+ it 'session has sort list param' do
138
+ expect(session[:list_params]['/crud_test_models.html']).to eq(
139
+ 'sort' => 'chatty', 'sort_dir' => 'desc')
140
140
  end
141
141
  end
142
142
 
@@ -145,15 +145,15 @@ describe CrudTestModelsController do
145
145
  { q: 'DDD', sort: 'chatty', sort_dir: 'asc' }
146
146
  end
147
147
 
148
- it_should_respond
148
+ it_is_expected_to_respond
149
149
 
150
- it 'entries should be in correct order' do
151
- entries.map(&:name).should == %w(CCCCC DDDDD BBBBB)
150
+ it 'entries are in correct order' do
151
+ expect(entries.map(&:name)).to eq(%w(CCCCC DDDDD BBBBB))
152
152
  end
153
153
 
154
- it 'session should have sort list param' do
155
- session[:list_params]['/crud_test_models.html'].should ==
156
- { q: 'DDD', sort: 'chatty', sort_dir: 'asc' }
154
+ it 'session has sort list param' do
155
+ expect(session[:list_params]['/crud_test_models.html']).to eq(
156
+ 'q' => 'DDD', 'sort' => 'chatty', 'sort_dir' => 'asc')
157
157
  end
158
158
  end
159
159
  end
@@ -161,12 +161,12 @@ describe CrudTestModelsController do
161
161
  context 'with custom options', combine: 'ihsoco' do
162
162
  let(:params) { { filter: true } }
163
163
 
164
- it_should_respond
164
+ it_is_expected_to_respond
165
165
 
166
166
  context 'entries' do
167
167
  subject { entries }
168
- it { should have(2).items }
169
- it { should == entries.sort_by(&:children).reverse }
168
+ it { expect(subject.size).to eq(2) }
169
+ it { is_expected.to eq(entries.sort_by(&:children).reverse) }
170
170
  end
171
171
  end
172
172
 
@@ -174,40 +174,40 @@ describe CrudTestModelsController do
174
174
  before do
175
175
  session[:list_params] = {}
176
176
  session[:list_params]['/crud_test_models'] =
177
- { q: 'DDD', sort: 'chatty', sort_dir: 'desc' }
177
+ { 'q' => 'DDD', 'sort' => 'chatty', 'sort_dir' => 'desc' }
178
178
  get :index, returning: true
179
179
  end
180
180
 
181
- it_should_respond
181
+ it_is_expected_to_respond
182
182
 
183
- it 'entries should be in correct order' do
184
- entries.map(&:name).should == %w(BBBBB DDDDD CCCCC)
183
+ it 'entries are in correct order' do
184
+ expect(entries.map(&:name)).to eq(%w(BBBBB DDDDD CCCCC))
185
185
  end
186
186
 
187
- it 'params should be set' do
188
- controller.params[:q].should == 'DDD'
189
- controller.params[:sort].should == 'chatty'
190
- controller.params[:sort_dir].should == 'desc'
187
+ it 'params are set' do
188
+ expect(controller.params[:q]).to eq('DDD')
189
+ expect(controller.params[:sort]).to eq('chatty')
190
+ expect(controller.params[:sort_dir]).to eq('desc')
191
191
  end
192
192
  end
193
193
  end
194
194
 
195
195
  context '.js', format: :js, combine: 'ijs' do
196
- it_should_respond
197
- it_should_assign_entries
198
- it { response.body.should == 'index js' }
196
+ it_is_expected_to_respond
197
+ it_is_expected_to_assign_entries
198
+ it { expect(response.body).to eq('index js') }
199
199
  end
200
200
  end
201
201
 
202
202
  describe_action :get, :new do
203
203
  context 'plain', combine: 'new' do
204
- it 'should assign companions' do
205
- assigns(:companions).should be_present
204
+ it 'assigns companions' do
205
+ expect(assigns(:companions)).to be_present
206
206
  end
207
207
 
208
- it 'should have called two render callbacks' do
209
- controller.called_callbacks.should ==
210
- [:before_render_new, :before_render_form]
208
+ it 'calls two render callbacks' do
209
+ expect(controller.called_callbacks).to eq(
210
+ [:before_render_new, :before_render_form])
211
211
  end
212
212
  end
213
213
 
@@ -218,10 +218,10 @@ describe CrudTestModelsController do
218
218
  get :new
219
219
  end
220
220
 
221
- it { should redirect_to(crud_test_models_path) }
221
+ it { is_expected.to redirect_to(crud_test_models_path) }
222
222
 
223
- it 'should not set companions' do
224
- assigns(:companions).should be_nil
223
+ it 'does not set companions' do
224
+ expect(assigns(:companions)).to be_nil
225
225
  end
226
226
  end
227
227
  end
@@ -229,54 +229,54 @@ describe CrudTestModelsController do
229
229
  describe_action :post, :create do
230
230
  let(:params) { { model_identifier => new_entry_attrs } }
231
231
 
232
- it 'should have called the correct callbacks' do
233
- controller.called_callbacks.should ==
234
- [:before_create, :before_save, :after_save, :after_create]
232
+ it 'calls the correct callbacks' do
233
+ expect(controller.called_callbacks).to eq(
234
+ [:before_create, :before_save, :after_save, :after_create])
235
235
  end
236
236
 
237
237
  context 'with before callback' do
238
238
  let(:params) do
239
239
  { crud_test_model: { name: 'illegal', children: 2 } }
240
240
  end
241
- it 'should not create entry', perform_request: false do
241
+ it 'does not create entry', perform_request: false do
242
242
  expect { perform_request }.to change { CrudTestModel.count }.by(0)
243
243
  end
244
244
 
245
245
  context 'plain', combine: 'chcp' do
246
- it_should_respond
247
- it_should_render('new')
248
- it_should_persist_entry(false)
249
- it_should_have_flash(:alert)
246
+ it_is_expected_to_respond
247
+ it_is_expected_to_render('new')
248
+ it_is_expected_to_persist_entry(false)
249
+ it_is_expected_to_have_flash(:alert)
250
250
 
251
- it 'should set entry name' do
252
- entry.name.should == 'illegal'
251
+ it 'sets entry name' do
252
+ expect(entry.name).to eq('illegal')
253
253
  end
254
254
 
255
- it 'should assign companions' do
256
- assigns(:companions).should be_present
255
+ it 'assigns companions' do
256
+ expect(assigns(:companions)).to be_present
257
257
  end
258
258
 
259
- it 'should have called the correct callbacks' do
260
- controller.called_callbacks.should ==
261
- [:before_render_new, :before_render_form]
259
+ it 'calls the correct callbacks' do
260
+ expect(controller.called_callbacks).to eq(
261
+ [:before_render_new, :before_render_form])
262
262
  end
263
263
  end
264
264
 
265
265
  context 'redirect', perform_request: false do
266
266
  before { controller.should_redirect = true }
267
267
 
268
- it 'should not create entry' do
268
+ it 'does not create entry' do
269
269
  expect { perform_request }.to change { CrudTestModel.count }.by(0)
270
270
  end
271
271
 
272
272
  it do
273
273
  perform_request
274
- should redirect_to(crud_test_models_path)
274
+ is_expected.to redirect_to(crud_test_models_path)
275
275
  end
276
276
 
277
- it 'should have called no callbacks' do
277
+ it 'calls no callbacks' do
278
278
  perform_request
279
- controller.called_callbacks.should be_nil
279
+ expect(controller.called_callbacks).to be_nil
280
280
  end
281
281
  end
282
282
  end
@@ -285,48 +285,48 @@ describe CrudTestModelsController do
285
285
  let(:params) { { crud_test_model: { children: 2 } } }
286
286
 
287
287
  context '.html' do
288
- it 'should not create entry', perform_request: false do
288
+ it 'does not create entry', perform_request: false do
289
289
  expect { perform_request }.to change { CrudTestModel.count }.by(0)
290
290
  end
291
291
 
292
292
  context 'plain', combine: 'chip' do
293
- it_should_respond
294
- it_should_render('new')
295
- it_should_persist_entry(false)
296
- it_should_not_have_flash(:notice)
297
- it_should_not_have_flash(:alert)
298
-
299
- it 'should assign companions' do
300
- assigns(:companions).should be_present
293
+ it_is_expected_to_respond
294
+ it_is_expected_to_render('new')
295
+ it_is_expected_to_persist_entry(false)
296
+ it_is_expected_to_not_have_flash(:notice)
297
+ it_is_expected_to_not_have_flash(:alert)
298
+
299
+ it 'assigns companions' do
300
+ expect(assigns(:companions)).to be_present
301
301
  end
302
302
 
303
- it 'should have called the correct callbacks' do
304
- controller.called_callbacks.should ==
303
+ it 'calls the correct callbacks' do
304
+ expect(controller.called_callbacks).to eq(
305
305
  [:before_create, :before_save,
306
- :before_render_new, :before_render_form]
306
+ :before_render_new, :before_render_form])
307
307
  end
308
308
  end
309
309
  end
310
310
 
311
311
  context '.json', format: :json do
312
- it 'should not create entry', perform_request: false do
312
+ it 'does not create entry', perform_request: false do
313
313
  expect { perform_request }.to change { CrudTestModel.count }.by(0)
314
314
  end
315
315
 
316
316
  context 'plain', combine: 'cjcb' do
317
- it_should_respond(422)
318
- it_should_persist_entry(false)
319
- it_should_not_have_flash(:notice)
320
- it_should_not_have_flash(:alert)
321
- it_should_render_error_json
322
-
323
- it 'should not assign companions' do
324
- assigns(:companions).should be_nil
317
+ it_is_expected_to_respond(422)
318
+ it_is_expected_to_persist_entry(false)
319
+ it_is_expected_to_not_have_flash(:notice)
320
+ it_is_expected_to_not_have_flash(:alert)
321
+ it_is_expected_to_render_json
322
+
323
+ it 'does not assign companions' do
324
+ expect(assigns(:companions)).to be_nil
325
325
  end
326
326
 
327
- it 'should have called the correct callbacks' do
328
- controller.called_callbacks.should ==
329
- [:before_create, :before_save]
327
+ it 'calls the correct callbacks' do
328
+ expect(controller.called_callbacks).to eq(
329
+ [:before_create, :before_save])
330
330
  end
331
331
  end
332
332
  end
@@ -335,50 +335,51 @@ describe CrudTestModelsController do
335
335
  end
336
336
 
337
337
  describe_action :get, :edit, id: true do
338
- it 'should have called the correct callbacks' do
339
- controller.called_callbacks.should ==
340
- [:before_render_edit, :before_render_form]
338
+ it 'calls the correct callbacks' do
339
+ expect(controller.called_callbacks).to eq(
340
+ [:before_render_edit, :before_render_form])
341
341
  end
342
342
  end
343
343
 
344
344
  describe_action :put, :update, id: true do
345
345
  let(:params) { { model_identifier => edit_entry_attrs } }
346
346
 
347
- it 'should have called the correct callbacks' do
348
- controller.called_callbacks.should ==
349
- [:before_update, :before_save, :after_save, :after_update]
347
+ it 'calls the correct callbacks' do
348
+ expect(controller.called_callbacks).to eq(
349
+ [:before_update, :before_save, :after_save, :after_update])
350
350
  end
351
351
 
352
352
  context 'with invalid params' do
353
353
  let(:params) { { crud_test_model: { rating: 20 } } }
354
354
 
355
355
  context '.html', combine: 'uhivp' do
356
- it_should_respond
357
- it_should_render('edit')
358
- it_should_not_have_flash(:notice)
356
+ it_is_expected_to_respond
357
+ it_is_expected_to_render('edit')
358
+ it_is_expected_to_not_have_flash(:notice)
359
359
 
360
- it 'should change entry' do
361
- entry.should be_changed
360
+ it 'changes entry' do
361
+ expect(entry).to be_changed
362
362
  end
363
363
 
364
- it 'should set entry rating' do
365
- entry.rating.should == 20
364
+ it 'sets entry rating' do
365
+ expect(entry.rating).to eq(20)
366
366
  end
367
367
 
368
- it 'should have called the correct callbacks' do
369
- controller.called_callbacks.should ==
368
+ it 'calls the correct callbacks' do
369
+ expect(controller.called_callbacks).to eq(
370
370
  [:before_update, :before_save,
371
- :before_render_edit, :before_render_form]
371
+ :before_render_edit, :before_render_form])
372
372
  end
373
373
  end
374
374
 
375
375
  context '.json', format: :json, combine: 'ujivp' do
376
- it_should_respond(422)
377
- it_should_not_have_flash(:notice)
378
- it_should_render_error_json
376
+ it_is_expected_to_respond(422)
377
+ it_is_expected_to_not_have_flash(:notice)
378
+ it_is_expected_to_render_json
379
379
 
380
- it 'should have called the correct callbacks' do
381
- controller.called_callbacks.should == [:before_update, :before_save]
380
+ it 'calls the correct callbacks' do
381
+ expect(controller.called_callbacks).to eq(
382
+ [:before_update, :before_save])
382
383
  end
383
384
  end
384
385
  end
@@ -386,33 +387,34 @@ describe CrudTestModelsController do
386
387
  end
387
388
 
388
389
  describe_action :delete, :destroy, id: true do
389
- it 'should have called the correct callbacks' do
390
- controller.called_callbacks.should == [:before_destroy, :after_destroy]
390
+ it 'calls the correct callbacks' do
391
+ expect(controller.called_callbacks).to eq(
392
+ [:before_destroy, :after_destroy])
391
393
  end
392
394
 
393
395
  context 'with failure' do
394
396
  let(:test_entry) { crud_test_models(:BBBBB) }
395
397
  context '.html' do
396
- it 'should not delete entry from database',
398
+ it 'does not delete entry from database',
397
399
  perform_request: false do
398
400
  expect { perform_request }.not_to change { CrudTestModel.count }
399
401
  end
400
402
 
401
- it 'should redirect to referer',
403
+ it 'redirects to referer',
402
404
  perform_request: false do
403
405
  ref = @request.env['HTTP_REFERER'] = crud_test_model_url(test_entry)
404
406
  perform_request
405
- should redirect_to(ref)
407
+ is_expected.to redirect_to(ref)
406
408
  end
407
409
 
408
- it_should_have_flash(:alert, /companion/)
409
- it_should_not_have_flash(:notice)
410
+ it_is_expected_to_have_flash(:alert, /companion/)
411
+ it_is_expected_to_not_have_flash(:notice)
410
412
  end
411
413
 
412
414
  context '.json', format: :json, combine: 'djf' do
413
- it_should_respond(422)
414
- it_should_not_have_flash(:notice)
415
- it_should_render_error_json
415
+ it_is_expected_to_respond(422)
416
+ it_is_expected_to_not_have_flash(:notice)
417
+ it_is_expected_to_render_json
416
418
  end
417
419
 
418
420
  context 'callback', perform_request: false do
@@ -420,18 +422,18 @@ describe CrudTestModelsController do
420
422
  test_entry.update_attribute :name, 'illegal'
421
423
  end
422
424
 
423
- it 'should not delete entry from database' do
425
+ it 'does not delete entry from database' do
424
426
  expect { perform_request }.not_to change { CrudTestModel.count }
425
427
  end
426
428
 
427
- it 'should redirect to index' do
429
+ it 'redirects to index' do
428
430
  perform_request
429
- should redirect_to(crud_test_models_path(returning: true))
431
+ is_expected.to redirect_to(crud_test_models_path(returning: true))
430
432
  end
431
433
 
432
- it 'should have flash alert' do
434
+ it 'has flash alert' do
433
435
  perform_request
434
- flash[:alert].should match(/illegal name/)
436
+ expect(flash[:alert]).to match(/illegal name/)
435
437
  end
436
438
  end
437
439
  end