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,98 +1,98 @@
1
- require 'spec_helper'
2
-
3
- describe CitiesController, '-> JSON', type: :controller do
4
-
5
- it 'Index -> GET /parent_resource/:parent_id/resources.json' do
6
- country = create :country
7
- 3.times { create :city, country: country }
8
-
9
- get :index, format: :json, country_id: 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 City.find(attributes['id']).name
15
- end
16
- end
17
-
18
- it 'Show -> GET /parent_resource/:parent_id/resources/:id.json' do
19
- city = create :city
20
-
21
- get :show, format: :json, id: city.id, country_id: 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 city.id
27
- attributes['name'].should eq city.name
28
- attributes['country_id'].should eq city.country.id
29
- end
30
-
31
- context 'Create -> POST /parent_resource/:parent_id/resources.json' do
32
-
33
- it 'Successfully' do
34
- country = create :country
35
- attributes = attributes_for :city
36
-
37
- post :create, format: :json, city: attributes, country_id: country.id
38
-
39
- response.status.should eq 201 # Created
40
- response.content_type.should eq 'application/json'
41
- city = JSON.parse(response.body)
42
- city['id'].should_not be_nil
43
- city['name'].should eq attributes[:name]
44
- city['country_id'].should eq country.id
45
-
46
- City.find_by_id(city['id']).should_not be_nil
47
- end
48
-
49
- it 'With errors' do
50
- country = create :country
51
-
52
- post :create, format: :json, country_id: 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 /parent_resource/:parent_id/resources/:id.json' do
62
-
63
- it 'Successfully' do
64
- city = create :city
65
- attributes = {name: "#{city.name} updated"}
66
-
67
- put :update, format: :json, id: city.id, city: attributes, country_id: city.country_id
68
-
69
- response.status.should eq 204 # No Content
70
- response.content_type.should eq 'application/json'
71
-
72
- City.find(city.id).name.should eq attributes[:name]
73
- end
74
-
75
- it 'With errors' do
76
- city = create :city
77
-
78
- put :update, format: :json, id: city.id, city: {name: nil}, country_id: 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 /parent_resource/:parent_id/resources/:id.json' do
88
- city = create :city
89
-
90
- delete :destroy, format: :json, id: city.id, country_id: city.country_id
91
-
92
- response.status.should eq 204 # No Content
93
- response.content_type.should eq 'application/json'
94
-
95
- City.find_by_id(city.id).should be_nil
96
- end
97
-
1
+ require 'spec_helper'
2
+
3
+ describe CitiesController, '-> JSON', type: :controller do
4
+
5
+ it 'Index -> GET /parent_resource/:parent_id/resources.json' do
6
+ country = create :country
7
+ 3.times { create :city, country: country }
8
+
9
+ get :index, format: :json, country_id: 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 City.find(attributes['id']).name
15
+ end
16
+ end
17
+
18
+ it 'Show -> GET /parent_resource/:parent_id/resources/:id.json' do
19
+ city = create :city
20
+
21
+ get :show, format: :json, id: city.id, country_id: 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 city.id
27
+ attributes['name'].should eq city.name
28
+ attributes['country_id'].should eq city.country.id
29
+ end
30
+
31
+ context 'Create -> POST /parent_resource/:parent_id/resources.json' do
32
+
33
+ it 'Successfully' do
34
+ country = create :country
35
+ attributes = attributes_for :city
36
+
37
+ post :create, format: :json, city: attributes, country_id: country.id
38
+
39
+ response.status.should eq 201 # Created
40
+ response.content_type.should eq 'application/json'
41
+ city = JSON.parse(response.body)
42
+ city['id'].should_not be_nil
43
+ city['name'].should eq attributes[:name]
44
+ city['country_id'].should eq country.id
45
+
46
+ City.find_by_id(city['id']).should_not be_nil
47
+ end
48
+
49
+ it 'With errors' do
50
+ country = create :country
51
+
52
+ post :create, format: :json, country_id: 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 /parent_resource/:parent_id/resources/:id.json' do
62
+
63
+ it 'Successfully' do
64
+ city = create :city
65
+ attributes = {name: "#{city.name} updated"}
66
+
67
+ put :update, format: :json, id: city.id, city: attributes, country_id: city.country_id
68
+
69
+ response.status.should eq 204 # No Content
70
+ response.content_type.should eq 'application/json'
71
+
72
+ City.find(city.id).name.should eq attributes[:name]
73
+ end
74
+
75
+ it 'With errors' do
76
+ city = create :city
77
+
78
+ put :update, format: :json, id: city.id, city: {name: nil}, country_id: 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 /parent_resource/:parent_id/resources/:id.json' do
88
+ city = create :city
89
+
90
+ delete :destroy, format: :json, id: city.id, country_id: city.country_id
91
+
92
+ response.status.should eq 204 # No Content
93
+ response.content_type.should eq 'application/json'
94
+
95
+ City.find_by_id(city.id).should be_nil
96
+ end
97
+
98
98
  end
@@ -1,58 +1,58 @@
1
- require 'spec_helper'
2
-
3
- describe CountriesController, '-> Ransack query search', type: :controller do
4
-
5
- it 'Filter by q[name_eq]' do
6
- 3.times { create :country }
7
-
8
- country = Country.first
9
-
10
- get :index, q: {name_eq: country.name}
11
-
12
- response.should be_success
13
- assigns(:countries).should eq [country]
14
- end
15
-
16
- it 'Filter by attribute, predicate and value' do
17
- 3.times { create :country }
18
-
19
- country = Country.first
20
-
21
- get :index, q: {c: [{a: {'0' => {name: 'name'}}, p: 'eq', v: {'0' => {value: country.name}}}]}
22
-
23
- response.should be_success
24
- assigns(:countries).should eq [country]
25
- end
26
-
27
- it 'Filter by NQL' do
28
- 3.times { create :country }
29
-
30
- country = Country.first
31
-
32
- get :index, q: "name = #{country.name}"
33
-
34
- response.should be_success
35
- assigns(:countries).should eq [country]
36
- end
37
-
38
- it 'Filter by NQL with invalid field' do
39
- 3.times { create :country }
40
-
41
- country = Country.first
42
-
43
- get :index, q: "abcd = #{country.name}"
44
-
45
- response.should be_success
46
- assigns(:countries).should eq []
47
- end
48
-
49
- it 'Filter by NQL with invalid expression' do
50
- 3.times { create :country }
51
-
52
- get :index, q: 'abcd = '
53
-
54
- response.should be_success
55
- assigns(:countries).should eq []
56
- end
57
-
1
+ require 'spec_helper'
2
+
3
+ describe CountriesController, '-> Ransack query search', type: :controller do
4
+
5
+ it 'Filter by q[name_eq]' do
6
+ 3.times { create :country }
7
+
8
+ country = Country.first
9
+
10
+ get :index, q: {name_eq: country.name}
11
+
12
+ response.should be_success
13
+ assigns(:countries).should eq [country]
14
+ end
15
+
16
+ it 'Filter by attribute, predicate and value' do
17
+ 3.times { create :country }
18
+
19
+ country = Country.first
20
+
21
+ get :index, q: {c: [{a: {'0' => {name: 'name'}}, p: 'eq', v: {'0' => {value: country.name}}}]}
22
+
23
+ response.should be_success
24
+ assigns(:countries).should eq [country]
25
+ end
26
+
27
+ it 'Filter by NQL' do
28
+ 3.times { create :country }
29
+
30
+ country = Country.first
31
+
32
+ get :index, q: "name = #{country.name}"
33
+
34
+ response.should be_success
35
+ assigns(:countries).should eq [country]
36
+ end
37
+
38
+ it 'Filter by NQL with invalid field' do
39
+ 3.times { create :country }
40
+
41
+ country = Country.first
42
+
43
+ get :index, q: "abcd = #{country.name}"
44
+
45
+ response.should be_success
46
+ assigns(:countries).should eq []
47
+ end
48
+
49
+ it 'Filter by NQL with invalid expression' do
50
+ 3.times { create :country }
51
+
52
+ get :index, q: 'abcd = '
53
+
54
+ response.should be_success
55
+ assigns(:countries).should eq []
56
+ end
57
+
58
58
  end
@@ -1,112 +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
-
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
112
  end