dynamic_controller 0.0.8 → 0.0.9

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 (49) hide show
  1. data/README.md +80 -80
  2. data/dynamic_controller.gemspec +27 -27
  3. data/lib/dynamic_controller/action_controller_extension.rb +18 -16
  4. data/lib/dynamic_controller/class_methods.rb +41 -41
  5. data/lib/dynamic_controller/helper_methods.rb +103 -91
  6. data/lib/dynamic_controller/instance_methods.rb +139 -139
  7. data/lib/dynamic_controller/resource.rb +21 -21
  8. data/lib/dynamic_controller/responder.rb +70 -70
  9. data/lib/dynamic_controller/version.rb +3 -3
  10. data/lib/dynamic_controller.rb +18 -18
  11. data/spec/controller_factory.rb +22 -22
  12. data/spec/controllers/crud_actions_html_spec.rb +111 -111
  13. data/spec/controllers/crud_actions_json_spec.rb +91 -91
  14. data/spec/controllers/nested_crud_actions_html_spec.rb +125 -125
  15. data/spec/controllers/nested_crud_actions_json_spec.rb +97 -97
  16. data/spec/controllers/ransack_spec.rb +57 -57
  17. data/spec/controllers/redefined_responders_html_spec.rb +111 -111
  18. data/spec/controllers/redefined_responders_json_spec.rb +94 -94
  19. data/spec/controllers/two_level_nested_crud_actions_html_spec.rb +133 -133
  20. data/spec/controllers/two_level_nested_crud_actions_json_spec.rb +97 -97
  21. data/spec/custom_responder_format_spec.rb +12 -12
  22. data/spec/dummy/Gemfile +13 -13
  23. data/spec/dummy/app/controllers/cities_controller.rb +95 -95
  24. data/spec/dummy/app/controllers/languages_controller.rb +95 -95
  25. data/spec/dummy/app/controllers/streets_controller.rb +97 -97
  26. data/spec/dummy/app/models/city.rb +6 -6
  27. data/spec/dummy/app/models/language.rb +4 -4
  28. data/spec/dummy/app/models/street.rb +5 -5
  29. data/spec/dummy/app/views/cities/_form.html.erb +25 -25
  30. data/spec/dummy/app/views/cities/index.html.erb +29 -29
  31. data/spec/dummy/app/views/countries/index.html.erb +25 -25
  32. data/spec/dummy/app/views/languages/_form.html.erb +21 -21
  33. data/spec/dummy/app/views/languages/edit.html.erb +6 -6
  34. data/spec/dummy/app/views/languages/index.html.erb +23 -23
  35. data/spec/dummy/app/views/languages/new.html.erb +5 -5
  36. data/spec/dummy/app/views/languages/show.html.erb +10 -10
  37. data/spec/dummy/app/views/streets/_form.html.erb +25 -25
  38. data/spec/dummy/app/views/streets/edit.html.erb +6 -6
  39. data/spec/dummy/app/views/streets/index.html.erb +27 -27
  40. data/spec/dummy/app/views/streets/new.html.erb +5 -5
  41. data/spec/dummy/app/views/streets/show.html.erb +15 -15
  42. data/spec/dummy/config/routes.rb +8 -8
  43. data/spec/dummy/db/migrate/20120922010743_create_languages.rb +9 -9
  44. data/spec/dummy/db/migrate/20120929185302_create_streets.rb +11 -11
  45. data/spec/dummy/db/schema.rb +46 -46
  46. data/spec/factories.rb +21 -21
  47. data/spec/has_crud_actions_options_spec.rb +48 -48
  48. data/spec/spec_helper.rb +35 -35
  49. metadata +58 -17
@@ -1,112 +1,112 @@
1
- require 'spec_helper'
2
-
3
- describe CountriesController, '-> HTML', type: :controller do
4
-
5
- it 'Index -> GET /resources' do
6
- 3.times { create :country }
7
-
8
- get :index
9
-
10
- response.should be_success
11
- response.content_type.should eq 'text/html'
12
- response.should render_template :index
13
- assigns(:countries).should eq Country.all
14
- end
15
-
16
- it 'Show -> GET /resources/:id' do
17
- country = create :country
18
-
19
- get :show, id: country.id
20
-
21
- response.should be_success
22
- response.content_type.should eq 'text/html'
23
- response.should render_template :show
24
- assigns(:country).should eq country
25
- end
26
-
27
- it 'New -> GET /resources/new' do
28
- get :new
29
-
30
- response.should be_success
31
- response.content_type.should eq 'text/html'
32
- response.should render_template :new
33
- assigns(:country).should be_a Country
34
- assigns(:country).should be_new_record
35
- end
36
-
37
- it 'Edit -> GET /resources/:id/edit' do
38
- country = create :country
39
-
40
- get :edit, id: country.id
41
-
42
- response.should be_success
43
- response.content_type.should eq 'text/html'
44
- response.should render_template :edit
45
- assigns(:country).should eq country
46
- end
47
-
48
- context 'Create -> POST /resources' do
49
-
50
- it 'Successfully' do
51
- attributes = attributes_for :country
52
-
53
- post :create, country: attributes
54
-
55
- response.should be_redirect
56
- response.content_type.should eq 'text/html'
57
- response.should redirect_to assigns(:country)
58
- assigns(:country).id.should_not be_nil
59
- assigns(:country).name.should eq attributes[:name]
60
- end
61
-
62
- it 'With errors' do
63
- post :create
64
-
65
- response.should be_success
66
- response.content_type.should eq 'text/html'
67
- response.should render_template :new
68
- assigns(:country).should have(1).errors_on(:name)
69
- end
70
-
71
- end
72
-
73
- context 'Update -> PUT /resources/:id' do
74
-
75
- it 'Successfully' do
76
- country = create :country
77
- attributes = {name: "#{country.name} updated"}
78
-
79
- put :update, id: country.id, country: attributes
80
-
81
- response.should be_redirect
82
- response.content_type.should eq 'text/html'
83
- response.should redirect_to country
84
- assigns(:country).name.should eq attributes[:name]
85
- end
86
-
87
- it 'With errors' do
88
- country = create :country
89
-
90
- put :update, id: country.id, country: {name: nil}
91
-
92
- response.should be_success
93
- response.content_type.should eq 'text/html'
94
- response.should render_template :edit
95
- assigns(:country).should have(1).errors_on(:name)
96
- end
97
-
98
- end
99
-
100
- it 'Destroy -> DELETE /resources/:id' do
101
- country = create :country
102
-
103
- delete :destroy, id: country.id
104
-
105
- response.should be_redirect
106
- response.content_type.should eq 'text/html'
107
- response.should redirect_to countries_path
108
-
109
- Country.find_by_id(country.id).should be_nil
110
- end
111
-
1
+ require 'spec_helper'
2
+
3
+ describe CountriesController, '-> HTML', type: :controller do
4
+
5
+ it 'Index -> GET /resources' do
6
+ 3.times { create :country }
7
+
8
+ get :index
9
+
10
+ response.should be_success
11
+ response.content_type.should eq 'text/html'
12
+ response.should render_template :index
13
+ assigns(:countries).should eq Country.all
14
+ end
15
+
16
+ it 'Show -> GET /resources/:id' do
17
+ country = create :country
18
+
19
+ get :show, id: country.id
20
+
21
+ response.should be_success
22
+ response.content_type.should eq 'text/html'
23
+ response.should render_template :show
24
+ assigns(:country).should eq country
25
+ end
26
+
27
+ it 'New -> GET /resources/new' do
28
+ get :new
29
+
30
+ response.should be_success
31
+ response.content_type.should eq 'text/html'
32
+ response.should render_template :new
33
+ assigns(:country).should be_a Country
34
+ assigns(:country).should be_new_record
35
+ end
36
+
37
+ it 'Edit -> GET /resources/:id/edit' do
38
+ country = create :country
39
+
40
+ get :edit, id: country.id
41
+
42
+ response.should be_success
43
+ response.content_type.should eq 'text/html'
44
+ response.should render_template :edit
45
+ assigns(:country).should eq country
46
+ end
47
+
48
+ context 'Create -> POST /resources' do
49
+
50
+ it 'Successfully' do
51
+ attributes = attributes_for :country
52
+
53
+ post :create, country: attributes
54
+
55
+ response.should be_redirect
56
+ response.content_type.should eq 'text/html'
57
+ response.should redirect_to assigns(:country)
58
+ assigns(:country).id.should_not be_nil
59
+ assigns(:country).name.should eq attributes[:name]
60
+ end
61
+
62
+ it 'With errors' do
63
+ post :create
64
+
65
+ response.should be_success
66
+ response.content_type.should eq 'text/html'
67
+ response.should render_template :new
68
+ assigns(:country).should have(1).errors_on(:name)
69
+ end
70
+
71
+ end
72
+
73
+ context 'Update -> PUT /resources/:id' do
74
+
75
+ it 'Successfully' do
76
+ country = create :country
77
+ attributes = {name: "#{country.name} updated"}
78
+
79
+ put :update, id: country.id, country: attributes
80
+
81
+ response.should be_redirect
82
+ response.content_type.should eq 'text/html'
83
+ response.should redirect_to country
84
+ assigns(:country).name.should eq attributes[:name]
85
+ end
86
+
87
+ it 'With errors' do
88
+ country = create :country
89
+
90
+ put :update, id: country.id, country: {name: nil}
91
+
92
+ response.should be_success
93
+ response.content_type.should eq 'text/html'
94
+ response.should render_template :edit
95
+ assigns(:country).should have(1).errors_on(:name)
96
+ end
97
+
98
+ end
99
+
100
+ it 'Destroy -> DELETE /resources/:id' do
101
+ country = create :country
102
+
103
+ delete :destroy, id: country.id
104
+
105
+ response.should be_redirect
106
+ response.content_type.should eq 'text/html'
107
+ response.should redirect_to countries_path
108
+
109
+ Country.find_by_id(country.id).should be_nil
110
+ end
111
+
112
112
  end
@@ -1,92 +1,92 @@
1
- require 'spec_helper'
2
-
3
- describe CountriesController, '-> JSON', type: :controller do
4
-
5
- it 'Index -> GET /resources.json' do
6
- 3.times { create :country }
7
-
8
- get :index, format: :json
9
-
10
- response.status.should eq 200 # OK
11
- response.content_type.should eq 'application/json'
12
- JSON.parse(response.body).each do |attributes|
13
- attributes['name'].should eq Country.find(attributes['id']).name
14
- end
15
- end
16
-
17
- it 'Show -> GET /resources/:id.json' do
18
- country = create :country
19
-
20
- get :show, format: :json, id: country.id
21
-
22
- response.status.should eq 200 # OK
23
- response.content_type.should eq 'application/json'
24
- attributes = JSON.parse(response.body)
25
- attributes['id'].should eq country.id
26
- attributes['name'].should eq country.name
27
- end
28
-
29
- context 'Create -> POST /resources.json' do
30
-
31
- it 'Successfully' do
32
- attributes = attributes_for :country
33
-
34
- post :create, format: :json, country: attributes
35
-
36
- response.status.should eq 201 # Created
37
- response.content_type.should eq 'application/json'
38
- country = JSON.parse(response.body)
39
- country['id'].should_not be_nil
40
- country['name'].should eq attributes[:name]
41
-
42
- Country.find_by_id(country['id']).should_not be_nil
43
- end
44
-
45
- it 'With errors' do
46
- post :create, format: :json
47
-
48
- response.status.should eq 422 # Unprocessable Entity
49
- response.content_type.should eq 'application/json'
50
- JSON.parse(response.body).should have_key 'name'
51
- end
52
-
53
- end
54
-
55
- context 'Update -> PUT /resources/:id.json' do
56
-
57
- it 'Successfully' do
58
- country = create :country
59
- attributes = {name: "#{country.name} updated"}
60
-
61
- put :update, format: :json, id: country.id, country: attributes
62
-
63
- response.status.should eq 204 # No Content
64
- response.content_type.should eq 'application/json'
65
-
66
- Country.find(country.id).name.should eq attributes[:name]
67
- end
68
-
69
- it 'With errors' do
70
- country = create :country
71
-
72
- put :update, format: :json, id: country.id, country: {name: nil}
73
-
74
- response.status.should eq 422 # Unprocessable Entity
75
- response.content_type.should eq 'application/json'
76
- JSON.parse(response.body).should have_key 'name'
77
- end
78
-
79
- end
80
-
81
- it 'Destroy -> DELETE /resources/:id.json' do
82
- country = create :country
83
-
84
- delete :destroy, format: :json, id: country.id
85
-
86
- response.status.should eq 204 # No Content
87
- response.content_type.should eq 'application/json'
88
-
89
- Country.find_by_id(country.id).should be_nil
90
- end
91
-
1
+ require 'spec_helper'
2
+
3
+ describe CountriesController, '-> JSON', type: :controller do
4
+
5
+ it 'Index -> GET /resources.json' do
6
+ 3.times { create :country }
7
+
8
+ get :index, format: :json
9
+
10
+ response.status.should eq 200 # OK
11
+ response.content_type.should eq 'application/json'
12
+ JSON.parse(response.body).each do |attributes|
13
+ attributes['name'].should eq Country.find(attributes['id']).name
14
+ end
15
+ end
16
+
17
+ it 'Show -> GET /resources/:id.json' do
18
+ country = create :country
19
+
20
+ get :show, format: :json, id: country.id
21
+
22
+ response.status.should eq 200 # OK
23
+ response.content_type.should eq 'application/json'
24
+ attributes = JSON.parse(response.body)
25
+ attributes['id'].should eq country.id
26
+ attributes['name'].should eq country.name
27
+ end
28
+
29
+ context 'Create -> POST /resources.json' do
30
+
31
+ it 'Successfully' do
32
+ attributes = attributes_for :country
33
+
34
+ post :create, format: :json, country: attributes
35
+
36
+ response.status.should eq 201 # Created
37
+ response.content_type.should eq 'application/json'
38
+ country = JSON.parse(response.body)
39
+ country['id'].should_not be_nil
40
+ country['name'].should eq attributes[:name]
41
+
42
+ Country.find_by_id(country['id']).should_not be_nil
43
+ end
44
+
45
+ it 'With errors' do
46
+ post :create, format: :json
47
+
48
+ response.status.should eq 422 # Unprocessable Entity
49
+ response.content_type.should eq 'application/json'
50
+ JSON.parse(response.body).should have_key 'name'
51
+ end
52
+
53
+ end
54
+
55
+ context 'Update -> PUT /resources/:id.json' do
56
+
57
+ it 'Successfully' do
58
+ country = create :country
59
+ attributes = {name: "#{country.name} updated"}
60
+
61
+ put :update, format: :json, id: country.id, country: attributes
62
+
63
+ response.status.should eq 204 # No Content
64
+ response.content_type.should eq 'application/json'
65
+
66
+ Country.find(country.id).name.should eq attributes[:name]
67
+ end
68
+
69
+ it 'With errors' do
70
+ country = create :country
71
+
72
+ put :update, format: :json, id: country.id, country: {name: nil}
73
+
74
+ response.status.should eq 422 # Unprocessable Entity
75
+ response.content_type.should eq 'application/json'
76
+ JSON.parse(response.body).should have_key 'name'
77
+ end
78
+
79
+ end
80
+
81
+ it 'Destroy -> DELETE /resources/:id.json' do
82
+ country = create :country
83
+
84
+ delete :destroy, format: :json, id: country.id
85
+
86
+ response.status.should eq 204 # No Content
87
+ response.content_type.should eq 'application/json'
88
+
89
+ Country.find_by_id(country.id).should be_nil
90
+ end
91
+
92
92
  end
@@ -1,126 +1,126 @@
1
- require 'spec_helper'
2
-
3
- describe CitiesController, '-> HTML', type: :controller do
4
-
5
- it 'Index -> GET /parent_resource/:parent_id/resources' do
6
- country = create :country
7
- 3.times { create :city, country: country }
8
-
9
- get :index, country_id: country.id
10
-
11
- response.should be_success
12
- response.content_type.should eq 'text/html'
13
- response.should render_template :index
14
- assigns(:cities).should eq City.all
15
- assigns(:country).should eq country
16
- end
17
-
18
- it 'Show -> GET /parent_resource/:parent_id/resources/:id' do
19
- city = create :city
20
-
21
- get :show, id: city.id, country_id: city.country_id
22
-
23
- response.should be_success
24
- response.content_type.should eq 'text/html'
25
- response.should render_template :show
26
- assigns(:city).should eq city
27
- assigns(:country).should eq city.country
28
- end
29
-
30
- it 'New -> GET /parent_resource/:parent_id/resources/new' do
31
- country = create :country
32
-
33
- get :new, country_id: country.id
34
-
35
- response.should be_success
36
- response.content_type.should eq 'text/html'
37
- response.should render_template :new
38
- assigns(:city).should be_a City
39
- assigns(:city).should be_new_record
40
- assigns(:country).should eq country
41
- end
42
-
43
- it 'Edit -> GET /parent_resource/:parent_id/resources/:id/edit' do
44
- city = create :city
45
-
46
- get :edit, id: city.id, country_id: city.country_id
47
-
48
- response.should be_success
49
- response.content_type.should eq 'text/html'
50
- response.should render_template :edit
51
- assigns(:city).should eq city
52
- assigns(:country).should eq city.country
53
- end
54
-
55
- context 'Create -> POST /parent_resource/:parent_id/resources' do
56
-
57
- it 'Successfully' do
58
- country = create :country
59
- attributes = attributes_for :city
60
-
61
- post :create, city: attributes, country_id: country.id
62
-
63
- response.should be_redirect
64
- response.content_type.should eq 'text/html'
65
- response.should redirect_to [country, assigns(:city)]
66
- assigns(:city).id.should_not be_nil
67
- assigns(:city).name.should eq attributes[:name]
68
- assigns(:country).should eq country
69
- end
70
-
71
- it 'With errors' do
72
- country = create :country
73
-
74
- post :create, country_id: country.id
75
-
76
- response.should be_success
77
- response.content_type.should eq 'text/html'
78
- response.should render_template :new
79
- assigns(:city).should have(1).errors_on(:name)
80
- assigns(:country).should eq country
81
- end
82
-
83
- end
84
-
85
- context 'Update -> PUT /parent_resource/:parent_id/resources/:id' do
86
-
87
- it 'Successfully' do
88
- city = create :city
89
- attributes = {name: "#{city.name} updated"}
90
-
91
- put :update, id: city.id, city: attributes, country_id: city.country_id
92
-
93
- response.should be_redirect
94
- response.content_type.should eq 'text/html'
95
- response.should redirect_to [city.country, city]
96
- assigns(:city).name.should eq attributes[:name]
97
- assigns(:country).should eq city.country
98
- end
99
-
100
- it 'With errors' do
101
- city = create :city
102
-
103
- put :update, id: city.id, city: {name: nil}, country_id: city.country_id
104
-
105
- response.should be_success
106
- response.content_type.should eq 'text/html'
107
- response.should render_template :edit
108
- assigns(:city).should have(1).errors_on(:name)
109
- assigns(:country).should eq city.country
110
- end
111
-
112
- end
113
-
114
- it 'Destroy -> DELETE /parent_resource/:parent_id/resources/:id' do
115
- city = create :city
116
-
117
- delete :destroy, id: city.id, country_id: city.country_id
118
-
119
- response.should be_redirect
120
- response.content_type.should eq 'text/html'
121
- response.should redirect_to country_cities_path(city.country)
122
-
123
- City.find_by_id(city.id).should be_nil
124
- end
125
-
1
+ require 'spec_helper'
2
+
3
+ describe CitiesController, '-> HTML', type: :controller do
4
+
5
+ it 'Index -> GET /parent_resource/:parent_id/resources' do
6
+ country = create :country
7
+ 3.times { create :city, country: country }
8
+
9
+ get :index, country_id: country.id
10
+
11
+ response.should be_success
12
+ response.content_type.should eq 'text/html'
13
+ response.should render_template :index
14
+ assigns(:cities).should eq City.all
15
+ assigns(:country).should eq country
16
+ end
17
+
18
+ it 'Show -> GET /parent_resource/:parent_id/resources/:id' do
19
+ city = create :city
20
+
21
+ get :show, id: city.id, country_id: city.country_id
22
+
23
+ response.should be_success
24
+ response.content_type.should eq 'text/html'
25
+ response.should render_template :show
26
+ assigns(:city).should eq city
27
+ assigns(:country).should eq city.country
28
+ end
29
+
30
+ it 'New -> GET /parent_resource/:parent_id/resources/new' do
31
+ country = create :country
32
+
33
+ get :new, country_id: country.id
34
+
35
+ response.should be_success
36
+ response.content_type.should eq 'text/html'
37
+ response.should render_template :new
38
+ assigns(:city).should be_a City
39
+ assigns(:city).should be_new_record
40
+ assigns(:country).should eq country
41
+ end
42
+
43
+ it 'Edit -> GET /parent_resource/:parent_id/resources/:id/edit' do
44
+ city = create :city
45
+
46
+ get :edit, id: city.id, country_id: city.country_id
47
+
48
+ response.should be_success
49
+ response.content_type.should eq 'text/html'
50
+ response.should render_template :edit
51
+ assigns(:city).should eq city
52
+ assigns(:country).should eq city.country
53
+ end
54
+
55
+ context 'Create -> POST /parent_resource/:parent_id/resources' do
56
+
57
+ it 'Successfully' do
58
+ country = create :country
59
+ attributes = attributes_for :city
60
+
61
+ post :create, city: attributes, country_id: country.id
62
+
63
+ response.should be_redirect
64
+ response.content_type.should eq 'text/html'
65
+ response.should redirect_to [country, assigns(:city)]
66
+ assigns(:city).id.should_not be_nil
67
+ assigns(:city).name.should eq attributes[:name]
68
+ assigns(:country).should eq country
69
+ end
70
+
71
+ it 'With errors' do
72
+ country = create :country
73
+
74
+ post :create, country_id: country.id
75
+
76
+ response.should be_success
77
+ response.content_type.should eq 'text/html'
78
+ response.should render_template :new
79
+ assigns(:city).should have(1).errors_on(:name)
80
+ assigns(:country).should eq country
81
+ end
82
+
83
+ end
84
+
85
+ context 'Update -> PUT /parent_resource/:parent_id/resources/:id' do
86
+
87
+ it 'Successfully' do
88
+ city = create :city
89
+ attributes = {name: "#{city.name} updated"}
90
+
91
+ put :update, id: city.id, city: attributes, country_id: city.country_id
92
+
93
+ response.should be_redirect
94
+ response.content_type.should eq 'text/html'
95
+ response.should redirect_to [city.country, city]
96
+ assigns(:city).name.should eq attributes[:name]
97
+ assigns(:country).should eq city.country
98
+ end
99
+
100
+ it 'With errors' do
101
+ city = create :city
102
+
103
+ put :update, id: city.id, city: {name: nil}, country_id: city.country_id
104
+
105
+ response.should be_success
106
+ response.content_type.should eq 'text/html'
107
+ response.should render_template :edit
108
+ assigns(:city).should have(1).errors_on(:name)
109
+ assigns(:country).should eq city.country
110
+ end
111
+
112
+ end
113
+
114
+ it 'Destroy -> DELETE /parent_resource/:parent_id/resources/:id' do
115
+ city = create :city
116
+
117
+ delete :destroy, id: city.id, country_id: city.country_id
118
+
119
+ response.should be_redirect
120
+ response.content_type.should eq 'text/html'
121
+ response.should redirect_to country_cities_path(city.country)
122
+
123
+ City.find_by_id(city.id).should be_nil
124
+ end
125
+
126
126
  end