dynamic_controller 0.0.1 → 0.0.2
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.
- data/.gitignore +4 -4
- data/Gemfile +4 -4
- data/README.md +39 -2
- data/Rakefile +1 -1
- data/dynamic_controller.gemspec +26 -26
- data/lib/dynamic_controller/class_methods.rb +48 -0
- data/lib/dynamic_controller/helper_methods.rb +59 -0
- data/lib/dynamic_controller/instance_methods.rb +127 -0
- data/lib/dynamic_controller/resource.rb +21 -0
- data/lib/dynamic_controller/responder.rb +71 -0
- data/lib/dynamic_controller/version.rb +3 -3
- data/lib/dynamic_controller.rb +12 -180
- data/spec/controller_factory.rb +15 -0
- data/spec/controllers/crud_actions_json_spec.rb +3 -3
- data/spec/controllers/nested_crud_actions_html_spec.rb +9 -8
- data/spec/controllers/nested_crud_actions_json_spec.rb +11 -11
- data/spec/controllers/redefined_responders_html_spec.rb +112 -0
- data/spec/controllers/redefined_responders_json_spec.rb +95 -0
- data/spec/controllers/two_level_nested_crud_actions_html_spec.rb +134 -0
- data/spec/controllers/two_level_nested_crud_actions_json_spec.rb +98 -0
- data/spec/dummy/.gitignore +15 -15
- data/spec/dummy/Gemfile +12 -12
- data/spec/dummy/README.rdoc +261 -261
- data/spec/dummy/Rakefile +7 -7
- data/spec/dummy/app/assets/javascripts/application.js +15 -15
- data/spec/dummy/app/assets/stylesheets/application.css +13 -13
- data/spec/dummy/app/assets/stylesheets/scaffolds.css.scss +69 -69
- data/spec/dummy/app/controllers/application_controller.rb +3 -3
- data/spec/dummy/app/controllers/cities_controller.rb +95 -94
- data/spec/dummy/app/controllers/countries_controller.rb +86 -86
- data/spec/dummy/app/controllers/languages_controller.rb +95 -0
- data/spec/dummy/app/controllers/streets_controller.rb +97 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/models/city.rb +6 -5
- data/spec/dummy/app/models/country.rb +5 -5
- data/spec/dummy/app/models/language.rb +4 -0
- data/spec/dummy/app/models/street.rb +5 -0
- data/spec/dummy/app/views/cities/_form.html.erb +25 -25
- data/spec/dummy/app/views/cities/edit.html.erb +6 -6
- data/spec/dummy/app/views/cities/index.html.erb +29 -25
- data/spec/dummy/app/views/cities/new.html.erb +5 -5
- data/spec/dummy/app/views/cities/show.html.erb +15 -15
- data/spec/dummy/app/views/countries/_form.html.erb +21 -21
- data/spec/dummy/app/views/countries/edit.html.erb +6 -6
- data/spec/dummy/app/views/countries/index.html.erb +25 -23
- data/spec/dummy/app/views/countries/new.html.erb +5 -5
- data/spec/dummy/app/views/countries/show.html.erb +10 -10
- data/spec/dummy/app/views/languages/_form.html.erb +21 -0
- data/spec/dummy/app/views/languages/edit.html.erb +6 -0
- data/spec/dummy/app/views/languages/index.html.erb +23 -0
- data/spec/dummy/app/views/languages/new.html.erb +5 -0
- data/spec/dummy/app/views/languages/show.html.erb +10 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -14
- data/spec/dummy/app/views/streets/_form.html.erb +25 -0
- data/spec/dummy/app/views/streets/edit.html.erb +6 -0
- data/spec/dummy/app/views/streets/index.html.erb +27 -0
- data/spec/dummy/app/views/streets/new.html.erb +5 -0
- data/spec/dummy/app/views/streets/show.html.erb +15 -0
- data/spec/dummy/config/application.rb +62 -62
- data/spec/dummy/config/boot.rb +6 -6
- data/spec/dummy/config/database.yml +25 -25
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +37 -37
- data/spec/dummy/config/environments/production.rb +67 -67
- data/spec/dummy/config/environments/test.rb +37 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/inflections.rb +15 -15
- data/spec/dummy/config/initializers/mime_types.rb +5 -5
- data/spec/dummy/config/initializers/secret_token.rb +7 -7
- data/spec/dummy/config/initializers/session_store.rb +8 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +5 -5
- data/spec/dummy/config/routes.rb +8 -5
- data/spec/dummy/config.ru +4 -4
- data/spec/dummy/db/migrate/20120907174827_create_countries.rb +9 -9
- data/spec/dummy/db/migrate/20120907230842_create_cities.rb +11 -11
- data/spec/dummy/db/migrate/20120922010743_create_languages.rb +9 -0
- data/spec/dummy/db/migrate/20120929185302_create_streets.rb +11 -0
- data/spec/dummy/db/schema.rb +16 -1
- data/spec/dummy/db/seeds.rb +7 -7
- data/spec/dummy/doc/README_FOR_APP +2 -2
- data/spec/dummy/public/404.html +26 -26
- data/spec/dummy/public/422.html +26 -26
- data/spec/dummy/public/500.html +25 -25
- data/spec/dummy/public/index.html +241 -241
- data/spec/dummy/public/robots.txt +5 -5
- data/spec/dummy/script/rails +6 -6
- data/spec/factories.rb +9 -0
- data/spec/has_crud_actions_options_spec.rb +49 -0
- data/spec/spec_helper.rb +1 -0
- metadata +43 -16
|
@@ -7,7 +7,7 @@ describe CountriesController, '-> JSON', type: :controller do
|
|
|
7
7
|
|
|
8
8
|
get :index, format: :json
|
|
9
9
|
|
|
10
|
-
response.status.should
|
|
10
|
+
response.status.should eq 200 # OK
|
|
11
11
|
response.content_type.should eq 'application/json'
|
|
12
12
|
JSON.parse(response.body).each do |attributes|
|
|
13
13
|
attributes['name'].should eq Country.find(attributes['id']).name
|
|
@@ -19,7 +19,7 @@ describe CountriesController, '-> JSON', type: :controller do
|
|
|
19
19
|
|
|
20
20
|
get :show, format: :json, id: country.id
|
|
21
21
|
|
|
22
|
-
response.status.should
|
|
22
|
+
response.status.should eq 200 # OK
|
|
23
23
|
response.content_type.should eq 'application/json'
|
|
24
24
|
attributes = JSON.parse(response.body)
|
|
25
25
|
attributes['id'].should eq country.id
|
|
@@ -33,7 +33,7 @@ describe CountriesController, '-> JSON', type: :controller do
|
|
|
33
33
|
|
|
34
34
|
post :create, format: :json, country: attributes
|
|
35
35
|
|
|
36
|
-
response.status.should
|
|
36
|
+
response.status.should eq 201 # Created
|
|
37
37
|
response.content_type.should eq 'application/json'
|
|
38
38
|
country = JSON.parse(response.body)
|
|
39
39
|
country['id'].should_not be_nil
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe CitiesController, '-> HTML', type: :controller do
|
|
4
4
|
|
|
5
|
-
it 'Index -> GET /resources' do
|
|
5
|
+
it 'Index -> GET /parent_resource/:parent_id/resources' do
|
|
6
6
|
country = create :country
|
|
7
7
|
3.times { create :city, country: country }
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ describe CitiesController, '-> HTML', type: :controller do
|
|
|
15
15
|
assigns(:country).should eq country
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
it 'Show -> GET /resources/:id' do
|
|
18
|
+
it 'Show -> GET /parent_resource/:parent_id/resources/:id' do
|
|
19
19
|
city = create :city
|
|
20
20
|
|
|
21
21
|
get :show, id: city.id, country_id: city.country_id
|
|
@@ -27,7 +27,7 @@ describe CitiesController, '-> HTML', type: :controller do
|
|
|
27
27
|
assigns(:country).should eq city.country
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
it 'New -> GET /resources/new' do
|
|
30
|
+
it 'New -> GET /parent_resource/:parent_id/resources/new' do
|
|
31
31
|
country = create :country
|
|
32
32
|
|
|
33
33
|
get :new, country_id: country.id
|
|
@@ -40,7 +40,7 @@ describe CitiesController, '-> HTML', type: :controller do
|
|
|
40
40
|
assigns(:country).should eq country
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
it 'Edit -> GET /resources/:id/edit' do
|
|
43
|
+
it 'Edit -> GET /parent_resource/:parent_id/resources/:id/edit' do
|
|
44
44
|
city = create :city
|
|
45
45
|
|
|
46
46
|
get :edit, id: city.id, country_id: city.country_id
|
|
@@ -52,11 +52,11 @@ describe CitiesController, '-> HTML', type: :controller do
|
|
|
52
52
|
assigns(:country).should eq city.country
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
context 'Create -> POST /resources' do
|
|
55
|
+
context 'Create -> POST /parent_resource/:parent_id/resources' do
|
|
56
56
|
|
|
57
57
|
it 'Successfully' do
|
|
58
58
|
country = create :country
|
|
59
|
-
attributes = attributes_for :city
|
|
59
|
+
attributes = attributes_for :city
|
|
60
60
|
|
|
61
61
|
post :create, city: attributes, country_id: country.id
|
|
62
62
|
|
|
@@ -70,6 +70,7 @@ describe CitiesController, '-> HTML', type: :controller do
|
|
|
70
70
|
|
|
71
71
|
it 'With errors' do
|
|
72
72
|
country = create :country
|
|
73
|
+
|
|
73
74
|
post :create, country_id: country.id
|
|
74
75
|
|
|
75
76
|
response.should be_success
|
|
@@ -81,7 +82,7 @@ describe CitiesController, '-> HTML', type: :controller do
|
|
|
81
82
|
|
|
82
83
|
end
|
|
83
84
|
|
|
84
|
-
context 'Update -> PUT /resources/:id' do
|
|
85
|
+
context 'Update -> PUT /parent_resource/:parent_id/resources/:id' do
|
|
85
86
|
|
|
86
87
|
it 'Successfully' do
|
|
87
88
|
city = create :city
|
|
@@ -110,7 +111,7 @@ describe CitiesController, '-> HTML', type: :controller do
|
|
|
110
111
|
|
|
111
112
|
end
|
|
112
113
|
|
|
113
|
-
it 'Destroy -> DELETE /resources/:id' do
|
|
114
|
+
it 'Destroy -> DELETE /parent_resource/:parent_id/resources/:id' do
|
|
114
115
|
city = create :city
|
|
115
116
|
|
|
116
117
|
delete :destroy, id: city.id, country_id: city.country_id
|
|
@@ -2,25 +2,25 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe CitiesController, '-> JSON', type: :controller do
|
|
4
4
|
|
|
5
|
-
it 'Index -> GET /resources.json' do
|
|
5
|
+
it 'Index -> GET /parent_resource/:parent_id/resources.json' do
|
|
6
6
|
country = create :country
|
|
7
7
|
3.times { create :city, country: country }
|
|
8
8
|
|
|
9
9
|
get :index, format: :json, country_id: country.id
|
|
10
10
|
|
|
11
|
-
response.status.should
|
|
11
|
+
response.status.should eq 200 # OK
|
|
12
12
|
response.content_type.should eq 'application/json'
|
|
13
13
|
JSON.parse(response.body).each do |attributes|
|
|
14
14
|
attributes['name'].should eq City.find(attributes['id']).name
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
it 'Show -> GET /resources/:id.json' do
|
|
18
|
+
it 'Show -> GET /parent_resource/:parent_id/resources/:id.json' do
|
|
19
19
|
city = create :city
|
|
20
20
|
|
|
21
21
|
get :show, format: :json, id: city.id, country_id: city.country.id
|
|
22
22
|
|
|
23
|
-
response.status.should
|
|
23
|
+
response.status.should eq 200 # OK
|
|
24
24
|
response.content_type.should eq 'application/json'
|
|
25
25
|
attributes = JSON.parse(response.body)
|
|
26
26
|
attributes['id'].should eq city.id
|
|
@@ -28,27 +28,27 @@ describe CitiesController, '-> JSON', type: :controller do
|
|
|
28
28
|
attributes['country_id'].should eq city.country.id
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
context 'Create -> POST /resources.json' do
|
|
31
|
+
context 'Create -> POST /parent_resource/:parent_id/resources.json' do
|
|
32
32
|
|
|
33
33
|
it 'Successfully' do
|
|
34
34
|
country = create :country
|
|
35
|
-
attributes = attributes_for :city
|
|
35
|
+
attributes = attributes_for :city
|
|
36
36
|
|
|
37
37
|
post :create, format: :json, city: attributes, country_id: country.id
|
|
38
|
-
puts response.body
|
|
39
38
|
|
|
40
|
-
response.status.should
|
|
39
|
+
response.status.should eq 201 # Created
|
|
41
40
|
response.content_type.should eq 'application/json'
|
|
42
41
|
city = JSON.parse(response.body)
|
|
43
42
|
city['id'].should_not be_nil
|
|
44
43
|
city['name'].should eq attributes[:name]
|
|
45
|
-
city['country_id'].should eq
|
|
44
|
+
city['country_id'].should eq country.id
|
|
46
45
|
|
|
47
46
|
City.find_by_id(city['id']).should_not be_nil
|
|
48
47
|
end
|
|
49
48
|
|
|
50
49
|
it 'With errors' do
|
|
51
50
|
country = create :country
|
|
51
|
+
|
|
52
52
|
post :create, format: :json, country_id: country.id
|
|
53
53
|
|
|
54
54
|
response.status.should eq 422 # Unprocessable Entity
|
|
@@ -58,7 +58,7 @@ describe CitiesController, '-> JSON', type: :controller do
|
|
|
58
58
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
context 'Update -> PUT /resources/:id.json' do
|
|
61
|
+
context 'Update -> PUT /parent_resource/:parent_id/resources/:id.json' do
|
|
62
62
|
|
|
63
63
|
it 'Successfully' do
|
|
64
64
|
city = create :city
|
|
@@ -84,7 +84,7 @@ describe CitiesController, '-> JSON', type: :controller do
|
|
|
84
84
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
it 'Destroy -> DELETE /resources/:id.json' do
|
|
87
|
+
it 'Destroy -> DELETE /parent_resource/:parent_id/resources/:id.json' do
|
|
88
88
|
city = create :city
|
|
89
89
|
|
|
90
90
|
delete :destroy, format: :json, id: city.id, country_id: city.country_id
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe LanguagesController, '-> HTML', type: :controller do
|
|
4
|
+
|
|
5
|
+
it 'Index -> GET /resources' do
|
|
6
|
+
3.times { create :language }
|
|
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(:languages).should eq Language.all
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'Show -> GET /resources/:id' do
|
|
17
|
+
language = create :language
|
|
18
|
+
|
|
19
|
+
get :show, id: language.id
|
|
20
|
+
|
|
21
|
+
response.should be_success
|
|
22
|
+
response.content_type.should eq 'text/html'
|
|
23
|
+
response.should render_template :show
|
|
24
|
+
assigns(:language).should eq language
|
|
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(:language).should be_a Language
|
|
34
|
+
assigns(:language).should be_new_record
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'Edit -> GET /resources/:id/edit' do
|
|
38
|
+
language = create :language
|
|
39
|
+
|
|
40
|
+
get :edit, id: language.id
|
|
41
|
+
|
|
42
|
+
response.should be_success
|
|
43
|
+
response.content_type.should eq 'text/html'
|
|
44
|
+
response.should render_template :edit
|
|
45
|
+
assigns(:language).should eq language
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context 'Create -> POST /resources' do
|
|
49
|
+
|
|
50
|
+
it 'Successfully' do
|
|
51
|
+
attributes = attributes_for :language
|
|
52
|
+
|
|
53
|
+
post :create, language: attributes
|
|
54
|
+
|
|
55
|
+
response.should be_redirect
|
|
56
|
+
response.content_type.should eq 'text/html'
|
|
57
|
+
response.should redirect_to languages_path
|
|
58
|
+
assigns(:language).id.should_not be_nil
|
|
59
|
+
assigns(:language).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(:language).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
|
+
language = create :language
|
|
77
|
+
attributes = {name: "#{language.name} updated"}
|
|
78
|
+
|
|
79
|
+
put :update, id: language.id, language: attributes
|
|
80
|
+
|
|
81
|
+
response.should be_redirect
|
|
82
|
+
response.content_type.should eq 'text/html'
|
|
83
|
+
response.should redirect_to languages_path
|
|
84
|
+
assigns(:language).name.should eq attributes[:name]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'With errors' do
|
|
88
|
+
language = create :language
|
|
89
|
+
|
|
90
|
+
put :update, id: language.id, language: {name: nil}
|
|
91
|
+
|
|
92
|
+
response.should be_success
|
|
93
|
+
response.content_type.should eq 'text/html'
|
|
94
|
+
response.should render_template :edit
|
|
95
|
+
assigns(:language).should have(1).errors_on(:name)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'Destroy -> DELETE /resources/:id' do
|
|
101
|
+
language = create :language
|
|
102
|
+
|
|
103
|
+
delete :destroy, id: language.id
|
|
104
|
+
|
|
105
|
+
response.should be_redirect
|
|
106
|
+
response.content_type.should eq 'text/html'
|
|
107
|
+
response.should redirect_to languages_path
|
|
108
|
+
|
|
109
|
+
Language.find_by_id(language.id).should be_nil
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
@@ -0,0 +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
|
+
|
|
95
|
+
end
|
|
@@ -0,0 +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
|
+
|
|
134
|
+
end
|
|
@@ -0,0 +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
|
+
|
|
98
|
+
end
|
data/spec/dummy/.gitignore
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
|
2
|
-
#
|
|
3
|
-
# If you find yourself ignoring temporary files generated by your text editor
|
|
4
|
-
# or operating system, you probably want to add a global ignore instead:
|
|
5
|
-
# git config --global core.excludesfile ~/.gitignore_global
|
|
6
|
-
|
|
7
|
-
# Ignore bundler config
|
|
8
|
-
/.bundle
|
|
9
|
-
|
|
10
|
-
# Ignore the default SQLite database.
|
|
11
|
-
/db/*.sqlite3
|
|
12
|
-
|
|
13
|
-
# Ignore all logfiles and tempfiles.
|
|
14
|
-
/log/*.log
|
|
15
|
-
/tmp
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
|
2
|
+
#
|
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
|
6
|
+
|
|
7
|
+
# Ignore bundler config
|
|
8
|
+
/.bundle
|
|
9
|
+
|
|
10
|
+
# Ignore the default SQLite database.
|
|
11
|
+
/db/*.sqlite3
|
|
12
|
+
|
|
13
|
+
# Ignore all logfiles and tempfiles.
|
|
14
|
+
/log/*.log
|
|
15
|
+
/tmp
|
data/spec/dummy/Gemfile
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
|
-
gem 'rails', '3.2.8'
|
|
4
|
-
gem 'sqlite3'
|
|
5
|
-
gem 'dynamic_controller', path: "#{File.dirname(__FILE__)}../../../"
|
|
6
|
-
|
|
7
|
-
group :assets do
|
|
8
|
-
gem 'sass-rails', '~> 3.2.3'
|
|
9
|
-
gem 'coffee-rails', '~> 3.2.1'
|
|
10
|
-
gem 'uglifier', '>= 1.0.3'
|
|
11
|
-
end
|
|
12
|
-
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
gem 'rails', '3.2.8'
|
|
4
|
+
gem 'sqlite3'
|
|
5
|
+
gem 'dynamic_controller', path: "#{File.dirname(__FILE__)}../../../"
|
|
6
|
+
|
|
7
|
+
group :assets do
|
|
8
|
+
gem 'sass-rails', '~> 3.2.3'
|
|
9
|
+
gem 'coffee-rails', '~> 3.2.1'
|
|
10
|
+
gem 'uglifier', '>= 1.0.3'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
13
|
gem 'jquery-rails'
|