dry_crud 1.7.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +126 -87
- data/VERSION +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +42 -22
- data/lib/generators/dry_crud/templates/INSTALL +5 -5
- data/lib/generators/dry_crud/templates/app/assets/stylesheets/crud.scss +0 -20
- data/lib/generators/dry_crud/templates/app/assets/stylesheets/sample.scss +24 -4
- data/lib/generators/dry_crud/templates/app/controllers/crud/generic_model.rb +89 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/nestable.rb +70 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/rememberable.rb +64 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/render_callbacks.rb +46 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/responder.rb +31 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/searchable.rb +55 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/sortable.rb +63 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +66 -69
- data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +23 -326
- data/lib/generators/dry_crud/templates/app/helpers/actions_helper.rb +64 -0
- data/lib/generators/dry_crud/templates/app/helpers/crud/form_builder.rb +331 -0
- data/lib/generators/dry_crud/templates/app/helpers/crud/table_builder.rb +280 -0
- data/lib/generators/dry_crud/templates/app/helpers/form_helper.rb +52 -0
- data/lib/generators/dry_crud/templates/app/helpers/format_helper.rb +164 -0
- data/lib/generators/dry_crud/templates/app/helpers/i18n_helper.rb +85 -0
- data/lib/generators/dry_crud/templates/app/helpers/table_helper.rb +83 -0
- data/lib/generators/dry_crud/templates/app/helpers/utility_helper.rb +84 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.haml +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_index.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_index.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.haml +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_form.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_form.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.erb +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.haml +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/_flash.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +15 -7
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.haml +18 -8
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.haml +3 -3
- data/lib/generators/dry_crud/templates/app/views/list/index.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/list/index.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.erb +2 -4
- data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.haml +2 -3
- data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +5 -1
- data/lib/generators/dry_crud/templates/config/locales/crud.de.yml +64 -0
- data/lib/generators/dry_crud/templates/config/locales/{en_crud.yml → crud.en.yml} +2 -2
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +241 -231
- data/lib/generators/dry_crud/templates/spec/helpers/crud/form_builder_spec.rb +226 -0
- data/lib/generators/dry_crud/templates/spec/helpers/{standard_table_builder_spec.rb → crud/table_builder_spec.rb} +36 -34
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +238 -0
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +244 -0
- data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +132 -0
- data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +265 -0
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +74 -0
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +185 -100
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +58 -49
- data/lib/generators/dry_crud/templates/test/{functional → controllers}/crud_test_models_controller_test.rb +112 -91
- data/lib/generators/dry_crud/templates/test/{unit/helpers/standard_form_builder_test.rb → helpers/crud/form_builder_test.rb} +79 -62
- data/lib/generators/dry_crud/templates/test/{unit/helpers/standard_table_builder_test.rb → helpers/crud/table_builder_test.rb} +31 -28
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +85 -0
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +129 -0
- data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +163 -0
- data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +79 -0
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +217 -0
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +63 -0
- data/lib/generators/dry_crud/templates/test/{functional → support}/crud_controller_test_helper.rb +70 -59
- data/lib/generators/dry_crud/templates/test/{crud_test_model.rb → support/crud_test_model.rb} +107 -75
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +83 -0
- metadata +83 -146
- data/Rakefile +0 -211
- data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +0 -168
- data/lib/generators/dry_crud/templates/app/helpers/list_helper.rb +0 -27
- data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +0 -261
- data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +0 -304
- data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +0 -178
- data/lib/generators/dry_crud/templates/spec/helpers/crud_helper_spec.rb +0 -146
- data/lib/generators/dry_crud/templates/spec/helpers/list_helper_spec.rb +0 -154
- data/lib/generators/dry_crud/templates/spec/helpers/standard_form_builder_spec.rb +0 -215
- data/lib/generators/dry_crud/templates/spec/helpers/standard_helper_spec.rb +0 -387
- data/lib/generators/dry_crud/templates/test/custom_assertions.rb +0 -78
- data/lib/generators/dry_crud/templates/test/unit/custom_assertions_test.rb +0 -117
- data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +0 -111
- data/lib/generators/dry_crud/templates/test/unit/helpers/list_helper_test.rb +0 -123
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +0 -281
- data/test/templates/Gemfile +0 -46
- data/test/templates/app/controllers/admin/cities_controller.rb +0 -7
- data/test/templates/app/controllers/admin/countries_controller.rb +0 -13
- data/test/templates/app/controllers/ajax_controller.rb +0 -9
- data/test/templates/app/controllers/people_controller.rb +0 -13
- data/test/templates/app/controllers/vips_controller.rb +0 -19
- data/test/templates/app/helpers/cities_helper.rb +0 -9
- data/test/templates/app/helpers/people_helper.rb +0 -8
- data/test/templates/app/models/city.rb +0 -28
- data/test/templates/app/models/country.rb +0 -16
- data/test/templates/app/models/person.rb +0 -12
- data/test/templates/app/views/admin/cities/_actions_index.html.erb +0 -2
- data/test/templates/app/views/admin/cities/_actions_index.html.haml +0 -2
- data/test/templates/app/views/admin/cities/_attrs.html.erb +0 -1
- data/test/templates/app/views/admin/cities/_attrs.html.haml +0 -1
- data/test/templates/app/views/admin/cities/_form.html.erb +0 -7
- data/test/templates/app/views/admin/cities/_form.html.haml +0 -5
- data/test/templates/app/views/admin/cities/_hello.html.erb +0 -1
- data/test/templates/app/views/admin/cities/_hello.html.haml +0 -1
- data/test/templates/app/views/admin/cities/_list.html.erb +0 -3
- data/test/templates/app/views/admin/cities/_list.html.haml +0 -3
- data/test/templates/app/views/admin/countries/_list.html.erb +0 -4
- data/test/templates/app/views/admin/countries/_list.html.haml +0 -3
- data/test/templates/app/views/ajax/_actions_index.html.erb +0 -8
- data/test/templates/app/views/ajax/_actions_index.html.haml +0 -8
- data/test/templates/app/views/ajax/_actions_show.html.erb +0 -4
- data/test/templates/app/views/ajax/_actions_show.html.haml +0 -4
- data/test/templates/app/views/ajax/_form.html.erb +0 -2
- data/test/templates/app/views/ajax/_form.html.haml +0 -2
- data/test/templates/app/views/ajax/_hello.html.erb +0 -1
- data/test/templates/app/views/ajax/_hello.html.haml +0 -1
- data/test/templates/app/views/ajax/ajax.js.erb +0 -1
- data/test/templates/app/views/ajax/ajax.js.haml +0 -1
- data/test/templates/app/views/ajax/edit.js.erb +0 -1
- data/test/templates/app/views/ajax/edit.js.haml +0 -1
- data/test/templates/app/views/ajax/show.js.erb +0 -1
- data/test/templates/app/views/ajax/show.js.haml +0 -1
- data/test/templates/app/views/ajax/update.js.erb +0 -5
- data/test/templates/app/views/ajax/update.js.haml +0 -5
- data/test/templates/app/views/layouts/_nav.html.erb +0 -6
- data/test/templates/app/views/layouts/_nav.html.haml +0 -5
- data/test/templates/app/views/layouts/bootstrap.html.erb +0 -68
- data/test/templates/app/views/layouts/bootstrap.html.haml +0 -49
- data/test/templates/app/views/people/_attrs.html.erb +0 -5
- data/test/templates/app/views/people/_attrs.html.haml +0 -4
- data/test/templates/app/views/people/_list.html.erb +0 -1
- data/test/templates/app/views/people/_list.html.haml +0 -1
- data/test/templates/config/database.yml +0 -21
- data/test/templates/config/locales/en_cities.yml +0 -56
- data/test/templates/config/routes.rb +0 -32
- data/test/templates/db/migrate/20100511174904_create_people_and_cities.rb +0 -26
- data/test/templates/db/seeds.rb +0 -74
- data/test/templates/spec/controllers/admin/cities_controller_spec.rb +0 -74
- data/test/templates/spec/controllers/admin/countries_controller_spec.rb +0 -56
- data/test/templates/spec/controllers/people_controller_spec.rb +0 -80
- data/test/templates/spec/routing/cities_routing_spec.rb +0 -11
- data/test/templates/spec/routing/countries_routing_spec.rb +0 -11
- data/test/templates/test/fixtures/cities.yml +0 -11
- data/test/templates/test/fixtures/countries.yml +0 -11
- data/test/templates/test/fixtures/people.yml +0 -14
- data/test/templates/test/functional/admin/cities_controller_test.rb +0 -59
- data/test/templates/test/functional/admin/countries_controller_test.rb +0 -42
- data/test/templates/test/functional/people_controller_test.rb +0 -68
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe UtilityHelper do
|
5
|
+
|
6
|
+
include CrudTestHelper
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
reset_db
|
10
|
+
setup_db
|
11
|
+
create_test_data
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) { reset_db }
|
15
|
+
|
16
|
+
describe '#column_type' do
|
17
|
+
let(:model) { crud_test_models(:AAAAA) }
|
18
|
+
|
19
|
+
it 'should recognize types' do
|
20
|
+
column_type(model, :name).should == :string
|
21
|
+
column_type(model, :children).should == :integer
|
22
|
+
column_type(model, :companion_id).should == :integer
|
23
|
+
column_type(model, :rating).should == :float
|
24
|
+
column_type(model, :income).should == :decimal
|
25
|
+
column_type(model, :birthdate).should == :date
|
26
|
+
column_type(model, :gets_up_at).should == :time
|
27
|
+
column_type(model, :last_seen).should == :datetime
|
28
|
+
column_type(model, :human).should == :boolean
|
29
|
+
column_type(model, :remarks).should == :text
|
30
|
+
column_type(model, :companion).should be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#content_tag_nested' do
|
35
|
+
|
36
|
+
it 'should escape safe content' do
|
37
|
+
html = content_tag_nested(:div, %w(a b)) { |e| content_tag(:span, e) }
|
38
|
+
html.should be_html_safe
|
39
|
+
html.should == '<div><span>a</span><span>b</span></div>'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should escape unsafe content' do
|
43
|
+
html = content_tag_nested(:div, %w(a b)) { |e| "<#{e}>" }
|
44
|
+
html.should == '<div><a><b></div>'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should simply join without block' do
|
48
|
+
html = content_tag_nested(:div, %w(a b))
|
49
|
+
html.should == '<div>ab</div>'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#safe_join' do
|
54
|
+
it 'should works as super without block' do
|
55
|
+
html = safe_join(['<a>', '<b>'.html_safe])
|
56
|
+
html.should == '<a><b>'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should collect contents for array' do
|
60
|
+
html = safe_join(%w(a b)) { |e| content_tag(:span, e) }
|
61
|
+
html.should == '<span>a</span><span>b</span>'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#default_crud_attrs' do
|
66
|
+
it 'do not contain id and password' do
|
67
|
+
default_crud_attrs.should ==
|
68
|
+
[:name, :email, :whatever, :children, :companion_id, :rating, :income,
|
69
|
+
:birthdate, :gets_up_at, :last_seen, :human, :remarks,
|
70
|
+
:created_at, :updated_at]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -1,163 +1,220 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require 'support/crud_controller_test_helper'
|
2
3
|
|
3
4
|
RSpec.configure do |c|
|
4
|
-
c.before :
|
5
|
+
c.before failing: true do
|
5
6
|
model_class.any_instance.stub(:save).and_return(false)
|
6
7
|
model_class.any_instance.stub(:destroy).and_return(false)
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
10
|
-
# A set of examples to include into the tests for your crud controller
|
11
|
-
# Simply #let :test_entry, :new_entry_attrs and :edit_entry_attrs
|
12
|
-
# crud functionality.
|
11
|
+
# A set of examples to include into the tests for your crud controller
|
12
|
+
# subclasses. Simply #let :test_entry, :new_entry_attrs and :edit_entry_attrs
|
13
|
+
# to test the basic crud functionality.
|
13
14
|
# If single examples do not match with you implementation, you may skip
|
14
15
|
# them by passing a skip parameter with context arrays:
|
15
|
-
# include_examples 'crud controller',
|
16
|
-
|
16
|
+
# include_examples 'crud controller',
|
17
|
+
# skip: [%w(index html sort) %w(destroy json)]
|
18
|
+
shared_examples 'crud controller' do |options|
|
17
19
|
|
18
20
|
include CrudControllerTestHelper
|
19
21
|
|
20
22
|
render_views
|
21
23
|
|
22
24
|
subject { response }
|
23
|
-
|
25
|
+
|
24
26
|
let(:model_class) { controller.send(:model_class) }
|
25
27
|
let(:model_identifier) { controller.model_identifier }
|
26
28
|
let(:test_params) { scope_params }
|
27
|
-
let(:entry) { assigns(controller.send(:ivar_name, model_class)) }
|
28
|
-
let(:entries) { assigns(controller.send(:ivar_name, model_class).pluralize) }
|
29
29
|
let(:sort_column) { model_class.column_names.first }
|
30
|
+
let(:entry) { assigns(controller.send(:ivar_name, model_class)) }
|
31
|
+
let(:entries) { assigns(controller.send(:ivar_name, model_class).pluralize) }
|
30
32
|
let(:search_value) do
|
31
33
|
field = controller.search_columns.first
|
32
34
|
val = test_entry[field].to_s
|
33
|
-
val[0..((val.size + 1)/ 2)]
|
35
|
+
val[0..((val.size + 1) / 2)]
|
34
36
|
end
|
35
37
|
|
36
38
|
before do
|
37
39
|
m = example.metadata
|
38
|
-
|
40
|
+
if m[:perform_request] != false && m[:action] && m[:method]
|
41
|
+
perform_combined_request
|
42
|
+
end
|
39
43
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
|
45
|
+
describe_action :get, :index,
|
46
|
+
unless: skip?(options, 'index') do
|
47
|
+
|
48
|
+
context '.html',
|
49
|
+
format: :html,
|
50
|
+
unless: skip?(options, %w(index html)) do
|
51
|
+
|
52
|
+
context 'plain',
|
53
|
+
unless: skip?(options, %w(index html plain)),
|
54
|
+
combine: 'ihp' do
|
46
55
|
it_should_respond
|
47
56
|
it_should_assign_entries
|
48
57
|
it_should_render
|
49
58
|
end
|
50
|
-
|
51
|
-
context
|
52
|
-
|
53
|
-
|
59
|
+
|
60
|
+
context 'search',
|
61
|
+
if: described_class.search_columns.present?,
|
62
|
+
unless: skip?(options, %w(index html search)),
|
63
|
+
combine: 'ihse' do
|
64
|
+
let(:params) { { q: search_value } }
|
65
|
+
|
54
66
|
it_should_respond
|
55
|
-
|
67
|
+
|
68
|
+
context 'entries' do
|
56
69
|
subject { entries }
|
57
70
|
it { should include(test_entry) }
|
58
71
|
end
|
59
72
|
end
|
60
|
-
|
61
|
-
context
|
62
|
-
|
63
|
-
|
64
|
-
|
73
|
+
|
74
|
+
context 'sort',
|
75
|
+
unless: skip?(options, %w(index html sort)) do
|
76
|
+
context 'ascending',
|
77
|
+
unless: skip?(options, %w(index html sort ascending)),
|
78
|
+
combine: 'ihso' do
|
79
|
+
let(:params) { { sort: sort_column, sort_dir: 'asc' } }
|
80
|
+
|
65
81
|
it_should_respond
|
66
|
-
|
82
|
+
|
83
|
+
it 'should have sorted entries' do
|
67
84
|
sorted = entries.sort_by(&(sort_column.to_sym))
|
68
85
|
entries.should == sorted
|
69
86
|
end
|
70
87
|
end
|
71
|
-
|
72
|
-
context
|
73
|
-
|
74
|
-
|
88
|
+
|
89
|
+
context 'descending',
|
90
|
+
unless: skip?(options, %w(index html sort descending)),
|
91
|
+
combine: 'ihsd' do
|
92
|
+
let(:params) { { sort: sort_column, sort_dir: 'desc' } }
|
93
|
+
|
75
94
|
it_should_respond
|
76
|
-
|
95
|
+
|
96
|
+
it 'should have sorted entries' do
|
77
97
|
sorted = entries.sort_by(&(sort_column.to_sym))
|
78
98
|
entries.should == sorted.reverse
|
79
99
|
end
|
80
100
|
end
|
81
101
|
end
|
82
102
|
end
|
83
|
-
|
84
|
-
context
|
103
|
+
|
104
|
+
context '.json',
|
105
|
+
format: :json,
|
106
|
+
unless: skip?(options, %w(index json)),
|
107
|
+
combine: 'ij' do
|
85
108
|
it_should_respond
|
86
109
|
it_should_assign_entries
|
87
110
|
its(:body) { should start_with('[{') }
|
88
111
|
end
|
89
112
|
end
|
90
|
-
|
91
|
-
describe_action :get, :show, :id => true, :unless => skip?(options, 'show') do
|
92
113
|
|
93
|
-
|
94
|
-
|
114
|
+
describe_action :get, :show,
|
115
|
+
id: true,
|
116
|
+
unless: skip?(options, 'show') do
|
117
|
+
|
118
|
+
context '.html',
|
119
|
+
format: :html,
|
120
|
+
unless: skip?(options, %w(show html)) do
|
121
|
+
|
122
|
+
context 'plain',
|
123
|
+
unless: skip?(options, %w(show html plain)),
|
124
|
+
combine: 'sh' do
|
95
125
|
it_should_respond
|
96
126
|
it_should_assign_entry
|
97
127
|
it_should_render
|
98
128
|
end
|
99
|
-
|
100
|
-
context
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
129
|
+
|
130
|
+
context 'with non-existing id',
|
131
|
+
unless: skip?(options,
|
132
|
+
%w(show html with_non_existing_id)) do
|
133
|
+
let(:params) { { id: 9999 } }
|
134
|
+
|
135
|
+
it 'should raise RecordNotFound', perform_request: false do
|
136
|
+
expect { perform_request }
|
137
|
+
.to raise_error(ActiveRecord::RecordNotFound)
|
105
138
|
end
|
106
139
|
end
|
107
140
|
end
|
108
|
-
|
109
|
-
context
|
141
|
+
|
142
|
+
context '.json',
|
143
|
+
format: :json,
|
144
|
+
unless: skip?(options, %w(show json)),
|
145
|
+
combine: 'sj' do
|
110
146
|
it_should_respond
|
111
147
|
it_should_assign_entry
|
112
148
|
its(:body) { should start_with('{') }
|
113
149
|
end
|
114
150
|
end
|
115
|
-
|
116
|
-
describe_action :get, :new,
|
117
|
-
|
151
|
+
|
152
|
+
describe_action :get, :new,
|
153
|
+
unless: skip?(options, %w(new)) do
|
154
|
+
context 'plain',
|
155
|
+
unless: skip?(options, %w(new plain)),
|
156
|
+
combine: 'new' do
|
118
157
|
it_should_respond
|
119
158
|
it_should_render
|
120
159
|
it_should_persist_entry(false)
|
121
160
|
end
|
122
|
-
|
123
|
-
context
|
161
|
+
|
162
|
+
context 'with params',
|
163
|
+
unless: skip?(options, %w(new with_params)) do
|
124
164
|
let(:params) { { model_identifier => new_entry_attrs } }
|
125
165
|
it_should_set_attrs(:new)
|
126
166
|
end
|
127
167
|
end
|
128
|
-
|
129
|
-
describe_action :post, :create,
|
168
|
+
|
169
|
+
describe_action :post, :create,
|
170
|
+
unless: skip?(options, %w(create)) do
|
130
171
|
let(:params) { { model_identifier => new_entry_attrs } }
|
131
|
-
|
132
|
-
it
|
172
|
+
|
173
|
+
it 'should add entry to database', perform_request: false do
|
133
174
|
expect { perform_request }.to change { model_class.count }.by(1)
|
134
175
|
end
|
135
|
-
|
136
|
-
context
|
137
|
-
|
176
|
+
|
177
|
+
context 'html',
|
178
|
+
format: :html,
|
179
|
+
unless: skip?(options, %w(create html)) do
|
180
|
+
it_should_persist_entry # cannot combine this
|
181
|
+
|
182
|
+
context 'with valid params',
|
183
|
+
unless: skip?(options, %w(create html valid)),
|
184
|
+
combine: 'chv' do
|
138
185
|
it_should_redirect_to_show
|
139
186
|
it_should_set_attrs(:new)
|
140
|
-
it_should_persist_entry
|
141
187
|
it_should_have_flash(:notice)
|
142
188
|
end
|
143
|
-
|
144
|
-
context
|
189
|
+
|
190
|
+
context 'with invalid params',
|
191
|
+
failing: true,
|
192
|
+
unless: skip?(options, %w(create html invalid)),
|
193
|
+
combine: 'chi' do
|
145
194
|
it_should_render('new')
|
146
195
|
it_should_persist_entry(false)
|
147
196
|
it_should_set_attrs(:new)
|
148
197
|
it_should_not_have_flash(:notice)
|
149
198
|
end
|
150
199
|
end
|
151
|
-
|
152
|
-
context
|
153
|
-
|
200
|
+
|
201
|
+
context 'json',
|
202
|
+
format: :json,
|
203
|
+
unless: skip?(options, %w(create json)) do
|
204
|
+
it_should_persist_entry # cannot combine this
|
205
|
+
|
206
|
+
context 'with valid params',
|
207
|
+
unless: skip?(options, %w(create json valid)),
|
208
|
+
combine: 'cjv' do
|
154
209
|
it_should_respond(201)
|
155
210
|
it_should_set_attrs(:new)
|
156
211
|
its(:body) { should start_with('{') }
|
157
|
-
it_should_persist_entry
|
158
212
|
end
|
159
|
-
|
160
|
-
context
|
213
|
+
|
214
|
+
context 'with invalid params',
|
215
|
+
failing: true,
|
216
|
+
unless: skip?(options, %w(create json invalid)),
|
217
|
+
combine: 'cji' do
|
161
218
|
it_should_respond(422)
|
162
219
|
it_should_set_attrs(:new)
|
163
220
|
its(:body) { should match(/"errors":\{/) }
|
@@ -165,80 +222,108 @@ shared_examples "crud controller" do |options|
|
|
165
222
|
end
|
166
223
|
end
|
167
224
|
end
|
168
|
-
|
169
|
-
describe_action :get, :edit,
|
225
|
+
|
226
|
+
describe_action :get, :edit,
|
227
|
+
id: true,
|
228
|
+
unless: skip?(options, %w(edit)),
|
229
|
+
combine: 'edit' do
|
170
230
|
it_should_respond
|
171
231
|
it_should_render
|
172
232
|
it_should_assign_entry
|
173
233
|
end
|
174
|
-
|
175
|
-
describe_action :put, :update,
|
176
|
-
|
177
|
-
|
178
|
-
|
234
|
+
|
235
|
+
describe_action :put, :update,
|
236
|
+
id: true,
|
237
|
+
unless: skip?(options, %w(update)) do
|
238
|
+
let(:params) { { model_identifier => edit_entry_attrs } }
|
239
|
+
|
240
|
+
it 'should update entry in database', perform_request: false do
|
179
241
|
expect { perform_request }.to change { model_class.count }.by(0)
|
180
242
|
end
|
181
|
-
|
182
|
-
context
|
183
|
-
|
243
|
+
|
244
|
+
context '.html',
|
245
|
+
format: :html,
|
246
|
+
unless: skip?(options, %w(update html)) do
|
247
|
+
context 'with valid params',
|
248
|
+
unless: skip?(options, %w(update html valid)),
|
249
|
+
combine: 'uhv' do
|
184
250
|
it_should_set_attrs(:edit)
|
185
251
|
it_should_redirect_to_show
|
186
252
|
it_should_persist_entry
|
187
253
|
it_should_have_flash(:notice)
|
188
254
|
end
|
189
|
-
|
190
|
-
context
|
255
|
+
|
256
|
+
context 'with invalid params',
|
257
|
+
failing: true,
|
258
|
+
unless: skip?(options, %w(update html invalid)),
|
259
|
+
combine: 'uhi' do
|
191
260
|
it_should_render('edit')
|
192
261
|
it_should_set_attrs(:edit)
|
193
262
|
it_should_not_have_flash(:notice)
|
194
263
|
end
|
195
264
|
end
|
196
|
-
|
197
|
-
context
|
198
|
-
|
265
|
+
|
266
|
+
context '.json',
|
267
|
+
format: :json,
|
268
|
+
unless: skip?(options, %w(update json)) do
|
269
|
+
|
270
|
+
context 'with valid params',
|
271
|
+
unless: skip?(options, %w(update json valid)),
|
272
|
+
combine: 'ujv' do
|
199
273
|
it_should_respond(204)
|
200
274
|
it_should_set_attrs(:edit)
|
201
275
|
its(:body) { should match(/s*/) }
|
202
276
|
it_should_persist_entry
|
203
277
|
end
|
204
|
-
|
205
|
-
context
|
278
|
+
|
279
|
+
context 'with invalid params',
|
280
|
+
failing: true,
|
281
|
+
unless: skip?(options, %w(update json invalid)),
|
282
|
+
combine: 'uji' do
|
206
283
|
it_should_respond(422)
|
207
284
|
it_should_set_attrs(:edit)
|
208
285
|
its(:body) { should match(/"errors":\{/) }
|
209
286
|
end
|
210
287
|
end
|
211
288
|
end
|
212
|
-
|
213
|
-
describe_action :delete, :destroy,
|
214
|
-
|
215
|
-
|
289
|
+
|
290
|
+
describe_action :delete, :destroy,
|
291
|
+
id: true,
|
292
|
+
unless: skip?(options, %w(destroy)) do
|
293
|
+
|
294
|
+
it 'should remove entry from database', perform_request: false do
|
216
295
|
expect { perform_request }.to change { model_class.count }.by(-1)
|
217
296
|
end
|
218
|
-
|
219
|
-
context
|
220
|
-
|
297
|
+
|
298
|
+
context '.html',
|
299
|
+
format: :html,
|
300
|
+
unless: skip?(options, %w(destroy html)) do
|
301
|
+
|
302
|
+
context 'successfull', combine: 'dhs' do
|
221
303
|
it_should_redirect_to_index
|
222
304
|
it_should_have_flash(:notice)
|
223
305
|
end
|
224
|
-
|
225
|
-
context
|
306
|
+
|
307
|
+
context 'with failure', failing: true, combine: 'dhf' do
|
226
308
|
it_should_redirect_to_index
|
227
309
|
it_should_have_flash(:alert)
|
228
310
|
end
|
229
311
|
end
|
230
|
-
|
231
|
-
context
|
232
|
-
|
312
|
+
|
313
|
+
context '.json',
|
314
|
+
format: :json,
|
315
|
+
unless: skip?(options, %w(destroy json)) do
|
316
|
+
|
317
|
+
context 'successfull', combine: 'djs' do
|
233
318
|
it_should_respond(204)
|
234
319
|
its(:body) { should match(/s*/) }
|
235
320
|
end
|
236
|
-
|
237
|
-
context
|
321
|
+
|
322
|
+
context 'with failure', failing: true, combine: 'djf' do
|
238
323
|
it_should_respond(422)
|
239
324
|
its(:body) { should match(/"errors":\{/) }
|
240
325
|
end
|
241
326
|
end
|
242
327
|
end
|
243
|
-
|
328
|
+
|
244
329
|
end
|