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,95 +1,95 @@
1
- require 'spec_helper'
2
-
3
- describe LanguagesController, '-> JSON', type: :controller do
4
-
5
- it 'Index -> GET /resources.json' do
6
- 3.times { create :language }
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 Language.find(attributes['id']).name
14
- end
15
- end
16
-
17
- it 'Show -> GET /resources/:id.json' do
18
- language = create :language
19
-
20
- get :show, format: :json, id: language.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 language.id
26
- attributes['name'].should eq language.name
27
- end
28
-
29
- context 'Create -> POST /resources.json' do
30
-
31
- it 'Successfully' do
32
- attributes = attributes_for :language
33
-
34
- post :create, format: :json, language: attributes
35
-
36
- response.status.should eq 201 # Created
37
- response.content_type.should eq 'application/json'
38
- language = JSON.parse(response.body)
39
- language['id'].should_not be_nil
40
- language['name'].should eq attributes[:name]
41
-
42
- Language.find_by_id(language['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
- language = create :language
59
- attributes = {name: "#{language.name} updated"}
60
-
61
- put :update, format: :json, id: language.id, language: attributes
62
-
63
- response.status.should eq 200 # Ok
64
- response.content_type.should eq 'application/json'
65
- json = JSON.parse(response.body)
66
- json['id'].should eq language.id
67
- json['name'].should eq attributes[:name]
68
-
69
- Language.find(language.id).name.should eq attributes[:name]
70
- end
71
-
72
- it 'With errors' do
73
- language = create :language
74
-
75
- put :update, format: :json, id: language.id, language: {name: nil}
76
-
77
- response.status.should eq 422 # Unprocessable Entity
78
- response.content_type.should eq 'application/json'
79
- JSON.parse(response.body).should have_key 'name'
80
- end
81
-
82
- end
83
-
84
- it 'Destroy -> DELETE /resources/:id.json' do
85
- language = create :language
86
-
87
- delete :destroy, format: :json, id: language.id
88
-
89
- response.status.should eq 204 # No Content
90
- response.content_type.should eq 'application/json'
91
-
92
- Language.find_by_id(language.id).should be_nil
93
- end
94
-
1
+ require 'spec_helper'
2
+
3
+ describe LanguagesController, '-> JSON', type: :controller do
4
+
5
+ it 'Index -> GET /resources.json' do
6
+ 3.times { create :language }
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 Language.find(attributes['id']).name
14
+ end
15
+ end
16
+
17
+ it 'Show -> GET /resources/:id.json' do
18
+ language = create :language
19
+
20
+ get :show, format: :json, id: language.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 language.id
26
+ attributes['name'].should eq language.name
27
+ end
28
+
29
+ context 'Create -> POST /resources.json' do
30
+
31
+ it 'Successfully' do
32
+ attributes = attributes_for :language
33
+
34
+ post :create, format: :json, language: attributes
35
+
36
+ response.status.should eq 201 # Created
37
+ response.content_type.should eq 'application/json'
38
+ language = JSON.parse(response.body)
39
+ language['id'].should_not be_nil
40
+ language['name'].should eq attributes[:name]
41
+
42
+ Language.find_by_id(language['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
+ language = create :language
59
+ attributes = {name: "#{language.name} updated"}
60
+
61
+ put :update, format: :json, id: language.id, language: attributes
62
+
63
+ response.status.should eq 200 # Ok
64
+ response.content_type.should eq 'application/json'
65
+ json = JSON.parse(response.body)
66
+ json['id'].should eq language.id
67
+ json['name'].should eq attributes[:name]
68
+
69
+ Language.find(language.id).name.should eq attributes[:name]
70
+ end
71
+
72
+ it 'With errors' do
73
+ language = create :language
74
+
75
+ put :update, format: :json, id: language.id, language: {name: nil}
76
+
77
+ response.status.should eq 422 # Unprocessable Entity
78
+ response.content_type.should eq 'application/json'
79
+ JSON.parse(response.body).should have_key 'name'
80
+ end
81
+
82
+ end
83
+
84
+ it 'Destroy -> DELETE /resources/:id.json' do
85
+ language = create :language
86
+
87
+ delete :destroy, format: :json, id: language.id
88
+
89
+ response.status.should eq 204 # No Content
90
+ response.content_type.should eq 'application/json'
91
+
92
+ Language.find_by_id(language.id).should be_nil
93
+ end
94
+
95
95
  end
@@ -1,134 +1,134 @@
1
- require 'spec_helper'
2
-
3
- describe StreetsController, '-> HTML', type: :controller do
4
-
5
- it 'Index -> GET /first_resource/:first_id/second_resource/:second_id/resources' do
6
- city = create :city
7
- 3.times { create :street, city: city }
8
-
9
- get :index, city_id: city.id, country_id: city.country.id
10
-
11
- response.should be_success
12
- response.content_type.should eq 'text/html'
13
- response.should render_template :index
14
- assigns(:streets).should eq Street.all
15
- assigns(:city).should eq city
16
- assigns(:country).should eq city.country
17
- end
18
-
19
- it 'Show -> GET /first_resource/:first_id/second_resource/:second_id/resources/:id' do
20
- street = create :street
21
-
22
- get :show, id: street.id, city_id: street.city_id, country_id: street.city.country.id
23
-
24
- response.should be_success
25
- response.content_type.should eq 'text/html'
26
- response.should render_template :show
27
- assigns(:street).should eq street
28
- assigns(:city).should eq street.city
29
- assigns(:country).should eq street.city.country
30
- end
31
-
32
- it 'New -> GET /first_resource/:first_id/second_resource/:second_id/resources/new' do
33
- city = create :city
34
-
35
- get :new, city_id: city.id, country_id: city.country.id
36
-
37
- response.should be_success
38
- response.content_type.should eq 'text/html'
39
- response.should render_template :new
40
- assigns(:street).should be_a Street
41
- assigns(:street).should be_new_record
42
- assigns(:city).should eq city
43
- assigns(:country).should eq city.country
44
- end
45
-
46
- it 'Edit -> GET /first_resource/:first_id/second_resource/:second_id/resources/:id/edit' do
47
- street = create :street
48
-
49
- get :edit, id: street.id, city_id: street.city_id, country_id: street.city.country.id
50
-
51
- response.should be_success
52
- response.content_type.should eq 'text/html'
53
- response.should render_template :edit
54
- assigns(:street).should eq street
55
- assigns(:city).should eq street.city
56
- assigns(:country).should eq street.city.country
57
- end
58
-
59
- context 'Create -> POST /first_resource/:first_id/second_resource/:second_id/resources' do
60
-
61
- it 'Successfully' do
62
- city = create :city
63
- attributes = attributes_for :street
64
-
65
- post :create, street: attributes, city_id: city.id, country_id: city.country.id
66
-
67
- response.should be_redirect
68
- response.content_type.should eq 'text/html'
69
- response.should redirect_to [city.country, city, assigns(:street)]
70
- assigns(:street).id.should_not be_nil
71
- assigns(:street).name.should eq attributes[:name]
72
- assigns(:city).should eq city
73
- assigns(:country).should eq city.country
74
- end
75
-
76
- it 'With errors' do
77
- city = create :city
78
-
79
- post :create, city_id: city.id, country_id: city.country.id, country_id: city.country.id
80
-
81
- response.should be_success
82
- response.content_type.should eq 'text/html'
83
- response.should render_template :new
84
- assigns(:street).should have(1).errors_on(:name)
85
- assigns(:city).should eq city
86
- assigns(:country).should eq city.country
87
- end
88
-
89
- end
90
-
91
- context 'Update -> PUT /first_resource/:first_id/second_resource/:second_id/resources/:id' do
92
-
93
- it 'Successfully' do
94
- street = create :street
95
- attributes = {name: "#{street.name} updated"}
96
-
97
- put :update, id: street.id, street: attributes, city_id: street.city_id, country_id: street.city.country.id
98
-
99
- response.should be_redirect
100
- response.content_type.should eq 'text/html'
101
- response.should redirect_to [street.city.country, street.city, street]
102
- assigns(:street).name.should eq attributes[:name]
103
- assigns(:city).should eq street.city
104
- assigns(:country).should eq street.city.country
105
- end
106
-
107
- it 'With errors' do
108
- street = create :street
109
-
110
- put :update, id: street.id, street: {name: nil}, city_id: street.city_id, country_id: street.city.country.id
111
-
112
- response.should be_success
113
- response.content_type.should eq 'text/html'
114
- response.should render_template :edit
115
- assigns(:street).should have(1).errors_on(:name)
116
- assigns(:city).should eq street.city
117
- assigns(:country).should eq street.city.country
118
- end
119
-
120
- end
121
-
122
- it 'Destroy -> DELETE /first_resource/:first_id/second_resource/:second_id/resources/:id' do
123
- street = create :street
124
-
125
- delete :destroy, id: street.id, city_id: street.city_id, country_id: street.city.country.id
126
-
127
- response.should be_redirect
128
- response.content_type.should eq 'text/html'
129
- response.should redirect_to country_city_streets_path(street.city.country, street.city)
130
-
131
- Street.find_by_id(street.id).should be_nil
132
- end
133
-
1
+ require 'spec_helper'
2
+
3
+ describe StreetsController, '-> HTML', type: :controller do
4
+
5
+ it 'Index -> GET /first_resource/:first_id/second_resource/:second_id/resources' do
6
+ city = create :city
7
+ 3.times { create :street, city: city }
8
+
9
+ get :index, city_id: city.id, country_id: city.country.id
10
+
11
+ response.should be_success
12
+ response.content_type.should eq 'text/html'
13
+ response.should render_template :index
14
+ assigns(:streets).should eq Street.all
15
+ assigns(:city).should eq city
16
+ assigns(:country).should eq city.country
17
+ end
18
+
19
+ it 'Show -> GET /first_resource/:first_id/second_resource/:second_id/resources/:id' do
20
+ street = create :street
21
+
22
+ get :show, id: street.id, city_id: street.city_id, country_id: street.city.country.id
23
+
24
+ response.should be_success
25
+ response.content_type.should eq 'text/html'
26
+ response.should render_template :show
27
+ assigns(:street).should eq street
28
+ assigns(:city).should eq street.city
29
+ assigns(:country).should eq street.city.country
30
+ end
31
+
32
+ it 'New -> GET /first_resource/:first_id/second_resource/:second_id/resources/new' do
33
+ city = create :city
34
+
35
+ get :new, city_id: city.id, country_id: city.country.id
36
+
37
+ response.should be_success
38
+ response.content_type.should eq 'text/html'
39
+ response.should render_template :new
40
+ assigns(:street).should be_a Street
41
+ assigns(:street).should be_new_record
42
+ assigns(:city).should eq city
43
+ assigns(:country).should eq city.country
44
+ end
45
+
46
+ it 'Edit -> GET /first_resource/:first_id/second_resource/:second_id/resources/:id/edit' do
47
+ street = create :street
48
+
49
+ get :edit, id: street.id, city_id: street.city_id, country_id: street.city.country.id
50
+
51
+ response.should be_success
52
+ response.content_type.should eq 'text/html'
53
+ response.should render_template :edit
54
+ assigns(:street).should eq street
55
+ assigns(:city).should eq street.city
56
+ assigns(:country).should eq street.city.country
57
+ end
58
+
59
+ context 'Create -> POST /first_resource/:first_id/second_resource/:second_id/resources' do
60
+
61
+ it 'Successfully' do
62
+ city = create :city
63
+ attributes = attributes_for :street
64
+
65
+ post :create, street: attributes, city_id: city.id, country_id: city.country.id
66
+
67
+ response.should be_redirect
68
+ response.content_type.should eq 'text/html'
69
+ response.should redirect_to [city.country, city, assigns(:street)]
70
+ assigns(:street).id.should_not be_nil
71
+ assigns(:street).name.should eq attributes[:name]
72
+ assigns(:city).should eq city
73
+ assigns(:country).should eq city.country
74
+ end
75
+
76
+ it 'With errors' do
77
+ city = create :city
78
+
79
+ post :create, city_id: city.id, country_id: city.country.id, country_id: city.country.id
80
+
81
+ response.should be_success
82
+ response.content_type.should eq 'text/html'
83
+ response.should render_template :new
84
+ assigns(:street).should have(1).errors_on(:name)
85
+ assigns(:city).should eq city
86
+ assigns(:country).should eq city.country
87
+ end
88
+
89
+ end
90
+
91
+ context 'Update -> PUT /first_resource/:first_id/second_resource/:second_id/resources/:id' do
92
+
93
+ it 'Successfully' do
94
+ street = create :street
95
+ attributes = {name: "#{street.name} updated"}
96
+
97
+ put :update, id: street.id, street: attributes, city_id: street.city_id, country_id: street.city.country.id
98
+
99
+ response.should be_redirect
100
+ response.content_type.should eq 'text/html'
101
+ response.should redirect_to [street.city.country, street.city, street]
102
+ assigns(:street).name.should eq attributes[:name]
103
+ assigns(:city).should eq street.city
104
+ assigns(:country).should eq street.city.country
105
+ end
106
+
107
+ it 'With errors' do
108
+ street = create :street
109
+
110
+ put :update, id: street.id, street: {name: nil}, city_id: street.city_id, country_id: street.city.country.id
111
+
112
+ response.should be_success
113
+ response.content_type.should eq 'text/html'
114
+ response.should render_template :edit
115
+ assigns(:street).should have(1).errors_on(:name)
116
+ assigns(:city).should eq street.city
117
+ assigns(:country).should eq street.city.country
118
+ end
119
+
120
+ end
121
+
122
+ it 'Destroy -> DELETE /first_resource/:first_id/second_resource/:second_id/resources/:id' do
123
+ street = create :street
124
+
125
+ delete :destroy, id: street.id, city_id: street.city_id, country_id: street.city.country.id
126
+
127
+ response.should be_redirect
128
+ response.content_type.should eq 'text/html'
129
+ response.should redirect_to country_city_streets_path(street.city.country, street.city)
130
+
131
+ Street.find_by_id(street.id).should be_nil
132
+ end
133
+
134
134
  end
@@ -1,98 +1,98 @@
1
- require 'spec_helper'
2
-
3
- describe StreetsController, '-> JSON', type: :controller do
4
-
5
- it 'Index -> GET /first_resource/:first_id/second_resource/:second_id/resources.json' do
6
- city = create :city
7
- 3.times { create :street, city: city }
8
-
9
- get :index, format: :json, city_id: city.id, country_id: city.country.id
10
-
11
- response.status.should eq 200 # OK
12
- response.content_type.should eq 'application/json'
13
- JSON.parse(response.body).each do |attributes|
14
- attributes['name'].should eq Street.find(attributes['id']).name
15
- end
16
- end
17
-
18
- it 'Show -> GET /first_resource/:first_id/second_resource/:second_id/resources/:id.json' do
19
- street = create :street
20
-
21
- get :show, format: :json, id: street.id, city_id: street.city.id, country_id: street.city.country.id
22
-
23
- response.status.should eq 200 # OK
24
- response.content_type.should eq 'application/json'
25
- attributes = JSON.parse(response.body)
26
- attributes['id'].should eq street.id
27
- attributes['name'].should eq street.name
28
- attributes['city_id'].should eq street.city.id
29
- end
30
-
31
- context 'Create -> POST /first_resource/:first_id/second_resource/:second_id/resources.json' do
32
-
33
- it 'Successfully' do
34
- city = create :city
35
- attributes = attributes_for :street
36
-
37
- post :create, format: :json, street: attributes, city_id: city.id, country_id: city.country.id
38
-
39
- response.status.should eq 201 # Created
40
- response.content_type.should eq 'application/json'
41
- street = JSON.parse(response.body)
42
- street['id'].should_not be_nil
43
- street['name'].should eq attributes[:name]
44
- street['city_id'].should eq city.id
45
-
46
- Street.find_by_id(street['id']).should_not be_nil
47
- end
48
-
49
- it 'With errors' do
50
- city = create :city
51
-
52
- post :create, format: :json, city_id: city.id, country_id: city.country.id
53
-
54
- response.status.should eq 422 # Unprocessable Entity
55
- response.content_type.should eq 'application/json'
56
- JSON.parse(response.body).should have_key 'name'
57
- end
58
-
59
- end
60
-
61
- context 'Update -> PUT /first_resource/:first_id/second_resource/:second_id/resources/:id.json' do
62
-
63
- it 'Successfully' do
64
- street = create :street
65
- attributes = {name: "#{street.name} updated"}
66
-
67
- put :update, format: :json, id: street.id, street: attributes, city_id: street.city_id, country_id: street.city.country.id
68
-
69
- response.status.should eq 204 # No Content
70
- response.content_type.should eq 'application/json'
71
-
72
- Street.find(street.id).name.should eq attributes[:name]
73
- end
74
-
75
- it 'With errors' do
76
- street = create :street
77
-
78
- put :update, format: :json, id: street.id, street: {name: nil}, city_id: street.city_id, country_id: street.city.country.id
79
-
80
- response.status.should eq 422 # Unprocessable Entity
81
- response.content_type.should eq 'application/json'
82
- JSON.parse(response.body).should have_key 'name'
83
- end
84
-
85
- end
86
-
87
- it 'Destroy -> DELETE /first_resource/:first_id/second_resource/:second_id/resources/:id.json' do
88
- street = create :street
89
-
90
- delete :destroy, format: :json, id: street.id, city_id: street.city_id, country_id: street.city.country.id
91
-
92
- response.status.should eq 204 # No Content
93
- response.content_type.should eq 'application/json'
94
-
95
- Street.find_by_id(street.id).should be_nil
96
- end
97
-
1
+ require 'spec_helper'
2
+
3
+ describe StreetsController, '-> JSON', type: :controller do
4
+
5
+ it 'Index -> GET /first_resource/:first_id/second_resource/:second_id/resources.json' do
6
+ city = create :city
7
+ 3.times { create :street, city: city }
8
+
9
+ get :index, format: :json, city_id: city.id, country_id: city.country.id
10
+
11
+ response.status.should eq 200 # OK
12
+ response.content_type.should eq 'application/json'
13
+ JSON.parse(response.body).each do |attributes|
14
+ attributes['name'].should eq Street.find(attributes['id']).name
15
+ end
16
+ end
17
+
18
+ it 'Show -> GET /first_resource/:first_id/second_resource/:second_id/resources/:id.json' do
19
+ street = create :street
20
+
21
+ get :show, format: :json, id: street.id, city_id: street.city.id, country_id: street.city.country.id
22
+
23
+ response.status.should eq 200 # OK
24
+ response.content_type.should eq 'application/json'
25
+ attributes = JSON.parse(response.body)
26
+ attributes['id'].should eq street.id
27
+ attributes['name'].should eq street.name
28
+ attributes['city_id'].should eq street.city.id
29
+ end
30
+
31
+ context 'Create -> POST /first_resource/:first_id/second_resource/:second_id/resources.json' do
32
+
33
+ it 'Successfully' do
34
+ city = create :city
35
+ attributes = attributes_for :street
36
+
37
+ post :create, format: :json, street: attributes, city_id: city.id, country_id: city.country.id
38
+
39
+ response.status.should eq 201 # Created
40
+ response.content_type.should eq 'application/json'
41
+ street = JSON.parse(response.body)
42
+ street['id'].should_not be_nil
43
+ street['name'].should eq attributes[:name]
44
+ street['city_id'].should eq city.id
45
+
46
+ Street.find_by_id(street['id']).should_not be_nil
47
+ end
48
+
49
+ it 'With errors' do
50
+ city = create :city
51
+
52
+ post :create, format: :json, city_id: city.id, country_id: city.country.id
53
+
54
+ response.status.should eq 422 # Unprocessable Entity
55
+ response.content_type.should eq 'application/json'
56
+ JSON.parse(response.body).should have_key 'name'
57
+ end
58
+
59
+ end
60
+
61
+ context 'Update -> PUT /first_resource/:first_id/second_resource/:second_id/resources/:id.json' do
62
+
63
+ it 'Successfully' do
64
+ street = create :street
65
+ attributes = {name: "#{street.name} updated"}
66
+
67
+ put :update, format: :json, id: street.id, street: attributes, city_id: street.city_id, country_id: street.city.country.id
68
+
69
+ response.status.should eq 204 # No Content
70
+ response.content_type.should eq 'application/json'
71
+
72
+ Street.find(street.id).name.should eq attributes[:name]
73
+ end
74
+
75
+ it 'With errors' do
76
+ street = create :street
77
+
78
+ put :update, format: :json, id: street.id, street: {name: nil}, city_id: street.city_id, country_id: street.city.country.id
79
+
80
+ response.status.should eq 422 # Unprocessable Entity
81
+ response.content_type.should eq 'application/json'
82
+ JSON.parse(response.body).should have_key 'name'
83
+ end
84
+
85
+ end
86
+
87
+ it 'Destroy -> DELETE /first_resource/:first_id/second_resource/:second_id/resources/:id.json' do
88
+ street = create :street
89
+
90
+ delete :destroy, format: :json, id: street.id, city_id: street.city_id, country_id: street.city.country.id
91
+
92
+ response.status.should eq 204 # No Content
93
+ response.content_type.should eq 'application/json'
94
+
95
+ Street.find_by_id(street.id).should be_nil
96
+ end
97
+
98
98
  end