dynamic_controller 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
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,13 +1,13 @@
1
- require 'spec_helper'
2
-
3
- describe 'Custom responder format' do
4
-
5
- it 'Respond only to HTML and JSON' do
6
- AllActionsController.responder_formats.should eq [:html, :json]
7
- end
8
-
9
- it 'Respond to XLS' do
10
- XlsResponderController.responder_formats.should eq [:html, :json, :xls]
11
- end
12
-
1
+ require 'spec_helper'
2
+
3
+ describe 'Custom responder format' do
4
+
5
+ it 'Respond only to HTML and JSON' do
6
+ AllActionsController.responder_formats.should eq [:html, :json]
7
+ end
8
+
9
+ it 'Respond to XLS' do
10
+ XlsResponderController.responder_formats.should eq [:html, :json, :xls]
11
+ end
12
+
13
13
  end
data/spec/dummy/Gemfile CHANGED
@@ -1,14 +1,14 @@
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
- gem 'therubyracer' if RUBY_PLATFORM.include? 'linux'
12
- end
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
+ gem 'therubyracer' if RUBY_PLATFORM.include? 'linux'
12
+ end
13
+
14
14
  gem 'jquery-rails'
@@ -1,95 +1,95 @@
1
- class CitiesController < ApplicationController
2
- has_crud_actions
3
- nested_of Country
4
- =begin
5
- before_filter :load_nested
6
-
7
- # GET /cities
8
- # GET /cities.json
9
- def index
10
- @cities = @country.cities
11
-
12
- respond_to do |format|
13
- format.html # index.html.erb
14
- format.json { render json: @cities }
15
- end
16
- end
17
-
18
- # GET /cities/1
19
- # GET /cities/1.json
20
- def show
21
- @city = @country.cities.find(params[:id])
22
-
23
- respond_to do |format|
24
- format.html # show.html.erb
25
- format.json { render json: @city }
26
- end
27
- end
28
-
29
- # GET /cities/new
30
- # GET /cities/new.json
31
- def new
32
- @city = @country.cities.build
33
-
34
- respond_to do |format|
35
- format.html # new.html.erb
36
- format.json { render json: @city }
37
- end
38
- end
39
-
40
- # GET /cities/1/edit
41
- def edit
42
- @city = @country.cities.find(params[:id])
43
- end
44
-
45
- # POST /cities
46
- # POST /cities.json
47
- def create
48
- @city = @country.cities.build(params[:city])
49
-
50
- respond_to do |format|
51
- if @city.save
52
- format.html { redirect_to [@country, @city], notice: 'City was successfully created.' }
53
- format.json { render json: @city, status: :created }
54
- else
55
- format.html { render action: "new" }
56
- format.json { render json: @city.errors, status: :unprocessable_entity }
57
- end
58
- end
59
- end
60
-
61
- # PUT /cities/1
62
- # PUT /cities/1.json
63
- def update
64
- @city = @country.cities.find(params[:id])
65
-
66
- respond_to do |format|
67
- if @city.update_attributes(params[:city])
68
- format.html { redirect_to [@country, @city], notice: 'City was successfully updated.' }
69
- format.json { head :no_content }
70
- else
71
- format.html { render action: "edit" }
72
- format.json { render json: @city.errors, status: :unprocessable_entity }
73
- end
74
- end
75
- end
76
-
77
- # DELETE /cities/1
78
- # DELETE /cities/1.json
79
- def destroy
80
- @city = @country.cities.find(params[:id])
81
- @city.destroy
82
-
83
- respond_to do |format|
84
- format.html { redirect_to country_cities_url(@country) }
85
- format.json { head :no_content }
86
- end
87
- end
88
-
89
- private
90
-
91
- def load_nested
92
- @country = Country.find(params[:country_id])
93
- end
94
- =end
95
- end
1
+ class CitiesController < ApplicationController
2
+ has_crud_actions
3
+ nested_of Country
4
+ =begin
5
+ before_filter :load_nested
6
+
7
+ # GET /cities
8
+ # GET /cities.json
9
+ def index
10
+ @cities = @country.cities
11
+
12
+ respond_to do |format|
13
+ format.html # index.html.erb
14
+ format.json { render json: @cities }
15
+ end
16
+ end
17
+
18
+ # GET /cities/1
19
+ # GET /cities/1.json
20
+ def show
21
+ @city = @country.cities.find(params[:id])
22
+
23
+ respond_to do |format|
24
+ format.html # show.html.erb
25
+ format.json { render json: @city }
26
+ end
27
+ end
28
+
29
+ # GET /cities/new
30
+ # GET /cities/new.json
31
+ def new
32
+ @city = @country.cities.build
33
+
34
+ respond_to do |format|
35
+ format.html # new.html.erb
36
+ format.json { render json: @city }
37
+ end
38
+ end
39
+
40
+ # GET /cities/1/edit
41
+ def edit
42
+ @city = @country.cities.find(params[:id])
43
+ end
44
+
45
+ # POST /cities
46
+ # POST /cities.json
47
+ def create
48
+ @city = @country.cities.build(params[:city])
49
+
50
+ respond_to do |format|
51
+ if @city.save
52
+ format.html { redirect_to [@country, @city], notice: 'City was successfully created.' }
53
+ format.json { render json: @city, status: :created }
54
+ else
55
+ format.html { render action: "new" }
56
+ format.json { render json: @city.errors, status: :unprocessable_entity }
57
+ end
58
+ end
59
+ end
60
+
61
+ # PUT /cities/1
62
+ # PUT /cities/1.json
63
+ def update
64
+ @city = @country.cities.find(params[:id])
65
+
66
+ respond_to do |format|
67
+ if @city.update_attributes(params[:city])
68
+ format.html { redirect_to [@country, @city], notice: 'City was successfully updated.' }
69
+ format.json { head :no_content }
70
+ else
71
+ format.html { render action: "edit" }
72
+ format.json { render json: @city.errors, status: :unprocessable_entity }
73
+ end
74
+ end
75
+ end
76
+
77
+ # DELETE /cities/1
78
+ # DELETE /cities/1.json
79
+ def destroy
80
+ @city = @country.cities.find(params[:id])
81
+ @city.destroy
82
+
83
+ respond_to do |format|
84
+ format.html { redirect_to country_cities_url(@country) }
85
+ format.json { head :no_content }
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ def load_nested
92
+ @country = Country.find(params[:country_id])
93
+ end
94
+ =end
95
+ end
@@ -1,95 +1,95 @@
1
- class LanguagesController < ApplicationController
2
- has_crud_actions
3
-
4
- respond_to_create :html do
5
- redirect_to action: :index
6
- end
7
-
8
- respond_to_update do |format|
9
- format.html { redirect_to action: :index }
10
- format.json { render json: @language }
11
- end
12
- =begin
13
- # GET /languages
14
- # GET /languages.json
15
- def index
16
- @languages = Language.all
17
-
18
- respond_to do |format|
19
- format.html # index.html.erb
20
- format.json { render json: @languages }
21
- end
22
- end
23
-
24
- # GET /languages/1
25
- # GET /languages/1.json
26
- def show
27
- @language = Language.find(params[:id])
28
-
29
- respond_to do |format|
30
- format.html # show.html.erb
31
- format.json { render json: @language }
32
- end
33
- end
34
-
35
- # GET /languages/new
36
- # GET /languages/new.json
37
- def new
38
- @language = Language.new
39
-
40
- respond_to do |format|
41
- format.html # new.html.erb
42
- format.json { render json: @language }
43
- end
44
- end
45
-
46
- # GET /languages/1/edit
47
- def edit
48
- @language = Language.find(params[:id])
49
- end
50
-
51
- # POST /languages
52
- # POST /languages.json
53
- def create
54
- @language = Language.new(params[:language])
55
-
56
- respond_to do |format|
57
- if @language.save
58
- format.html { redirect_to action: :index, notice: 'Language was successfully created.' }
59
- format.json { render json: @language, status: :created, location: @language }
60
- else
61
- format.html { render action: "new" }
62
- format.json { render json: @language.errors, status: :unprocessable_entity }
63
- end
64
- end
65
- end
66
-
67
- # PUT /languages/1
68
- # PUT /languages/1.json
69
- def update
70
- @language = Language.find(params[:id])
71
-
72
- respond_to do |format|
73
- if @language.update_attributes(params[:language])
74
- format.html { redirect_to action: :index, notice: 'Language was successfully updated.' }
75
- format.json { head :no_content }
76
- else
77
- format.html { render action: "edit" }
78
- format.json { render json: @language.errors, status: :unprocessable_entity }
79
- end
80
- end
81
- end
82
-
83
- # DELETE /languages/1
84
- # DELETE /languages/1.json
85
- def destroy
86
- @language = Language.find(params[:id])
87
- @language.destroy
88
-
89
- respond_to do |format|
90
- format.html { redirect_to languages_url }
91
- format.json { head :no_content }
92
- end
93
- end
94
- =end
95
- end
1
+ class LanguagesController < ApplicationController
2
+ has_crud_actions
3
+
4
+ respond_to_create :html do
5
+ redirect_to action: :index
6
+ end
7
+
8
+ respond_to_update do |format|
9
+ format.html { redirect_to action: :index }
10
+ format.json { render json: @language }
11
+ end
12
+ =begin
13
+ # GET /languages
14
+ # GET /languages.json
15
+ def index
16
+ @languages = Language.all
17
+
18
+ respond_to do |format|
19
+ format.html # index.html.erb
20
+ format.json { render json: @languages }
21
+ end
22
+ end
23
+
24
+ # GET /languages/1
25
+ # GET /languages/1.json
26
+ def show
27
+ @language = Language.find(params[:id])
28
+
29
+ respond_to do |format|
30
+ format.html # show.html.erb
31
+ format.json { render json: @language }
32
+ end
33
+ end
34
+
35
+ # GET /languages/new
36
+ # GET /languages/new.json
37
+ def new
38
+ @language = Language.new
39
+
40
+ respond_to do |format|
41
+ format.html # new.html.erb
42
+ format.json { render json: @language }
43
+ end
44
+ end
45
+
46
+ # GET /languages/1/edit
47
+ def edit
48
+ @language = Language.find(params[:id])
49
+ end
50
+
51
+ # POST /languages
52
+ # POST /languages.json
53
+ def create
54
+ @language = Language.new(params[:language])
55
+
56
+ respond_to do |format|
57
+ if @language.save
58
+ format.html { redirect_to action: :index, notice: 'Language was successfully created.' }
59
+ format.json { render json: @language, status: :created, location: @language }
60
+ else
61
+ format.html { render action: "new" }
62
+ format.json { render json: @language.errors, status: :unprocessable_entity }
63
+ end
64
+ end
65
+ end
66
+
67
+ # PUT /languages/1
68
+ # PUT /languages/1.json
69
+ def update
70
+ @language = Language.find(params[:id])
71
+
72
+ respond_to do |format|
73
+ if @language.update_attributes(params[:language])
74
+ format.html { redirect_to action: :index, notice: 'Language was successfully updated.' }
75
+ format.json { head :no_content }
76
+ else
77
+ format.html { render action: "edit" }
78
+ format.json { render json: @language.errors, status: :unprocessable_entity }
79
+ end
80
+ end
81
+ end
82
+
83
+ # DELETE /languages/1
84
+ # DELETE /languages/1.json
85
+ def destroy
86
+ @language = Language.find(params[:id])
87
+ @language.destroy
88
+
89
+ respond_to do |format|
90
+ format.html { redirect_to languages_url }
91
+ format.json { head :no_content }
92
+ end
93
+ end
94
+ =end
95
+ end
@@ -1,97 +1,97 @@
1
- class StreetsController < ApplicationController
2
- has_crud_actions
3
- nested_of Country
4
- nested_of City
5
- =begin
6
- before_filter :load_nested
7
-
8
- # GET /streets
9
- # GET /streets.json
10
- def index
11
- @streets = @city.streets
12
-
13
- respond_to do |format|
14
- format.html # index.html.erb
15
- format.json { render json: @streets }
16
- end
17
- end
18
-
19
- # GET /streets/1
20
- # GET /streets/1.json
21
- def show
22
- @street = @city.streets.find(params[:id])
23
-
24
- respond_to do |format|
25
- format.html # show.html.erb
26
- format.json { render json: @street }
27
- end
28
- end
29
-
30
- # GET /streets/new
31
- # GET /streets/new.json
32
- def new
33
- @street = @city.streets.build
34
-
35
- respond_to do |format|
36
- format.html # new.html.erb
37
- format.json { render json: @street }
38
- end
39
- end
40
-
41
- # GET /streets/1/edit
42
- def edit
43
- @street = @city.streets.find(params[:id])
44
- end
45
-
46
- # POST /streets
47
- # POST /streets.json
48
- def create
49
- @street = @city.streets.build(params[:street])
50
-
51
- respond_to do |format|
52
- if @street.save
53
- format.html { redirect_to [@country, @city, @street], notice: 'Street was successfully created.' }
54
- format.json { render json: @street, status: :created }
55
- else
56
- format.html { render action: "new" }
57
- format.json { render json: @street.errors, status: :unprocessable_entity }
58
- end
59
- end
60
- end
61
-
62
- # PUT /streets/1
63
- # PUT /streets/1.json
64
- def update
65
- @street = @city.streets.find(params[:id])
66
-
67
- respond_to do |format|
68
- if @street.update_attributes(params[:street])
69
- format.html { redirect_to [@country, @city, @street], notice: 'Street was successfully updated.' }
70
- format.json { head :no_content }
71
- else
72
- format.html { render action: "edit" }
73
- format.json { render json: @street.errors, status: :unprocessable_entity }
74
- end
75
- end
76
- end
77
-
78
- # DELETE /streets/1
79
- # DELETE /streets/1.json
80
- def destroy
81
- @street = @city.streets.find(params[:id])
82
- @street.destroy
83
-
84
- respond_to do |format|
85
- format.html { redirect_to country_city_streets_url(@country, @city) }
86
- format.json { head :no_content }
87
- end
88
- end
89
-
90
- private
91
-
92
- def load_nested
93
- @country = Country.find(params[:country_id])
94
- @city = @country.cities.find(params[:city_id])
95
- end
96
- =end
97
- end
1
+ class StreetsController < ApplicationController
2
+ has_crud_actions
3
+ nested_of Country
4
+ nested_of City
5
+ =begin
6
+ before_filter :load_nested
7
+
8
+ # GET /streets
9
+ # GET /streets.json
10
+ def index
11
+ @streets = @city.streets
12
+
13
+ respond_to do |format|
14
+ format.html # index.html.erb
15
+ format.json { render json: @streets }
16
+ end
17
+ end
18
+
19
+ # GET /streets/1
20
+ # GET /streets/1.json
21
+ def show
22
+ @street = @city.streets.find(params[:id])
23
+
24
+ respond_to do |format|
25
+ format.html # show.html.erb
26
+ format.json { render json: @street }
27
+ end
28
+ end
29
+
30
+ # GET /streets/new
31
+ # GET /streets/new.json
32
+ def new
33
+ @street = @city.streets.build
34
+
35
+ respond_to do |format|
36
+ format.html # new.html.erb
37
+ format.json { render json: @street }
38
+ end
39
+ end
40
+
41
+ # GET /streets/1/edit
42
+ def edit
43
+ @street = @city.streets.find(params[:id])
44
+ end
45
+
46
+ # POST /streets
47
+ # POST /streets.json
48
+ def create
49
+ @street = @city.streets.build(params[:street])
50
+
51
+ respond_to do |format|
52
+ if @street.save
53
+ format.html { redirect_to [@country, @city, @street], notice: 'Street was successfully created.' }
54
+ format.json { render json: @street, status: :created }
55
+ else
56
+ format.html { render action: "new" }
57
+ format.json { render json: @street.errors, status: :unprocessable_entity }
58
+ end
59
+ end
60
+ end
61
+
62
+ # PUT /streets/1
63
+ # PUT /streets/1.json
64
+ def update
65
+ @street = @city.streets.find(params[:id])
66
+
67
+ respond_to do |format|
68
+ if @street.update_attributes(params[:street])
69
+ format.html { redirect_to [@country, @city, @street], notice: 'Street was successfully updated.' }
70
+ format.json { head :no_content }
71
+ else
72
+ format.html { render action: "edit" }
73
+ format.json { render json: @street.errors, status: :unprocessable_entity }
74
+ end
75
+ end
76
+ end
77
+
78
+ # DELETE /streets/1
79
+ # DELETE /streets/1.json
80
+ def destroy
81
+ @street = @city.streets.find(params[:id])
82
+ @street.destroy
83
+
84
+ respond_to do |format|
85
+ format.html { redirect_to country_city_streets_url(@country, @city) }
86
+ format.json { head :no_content }
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ def load_nested
93
+ @country = Country.find(params[:country_id])
94
+ @city = @country.cities.find(params[:city_id])
95
+ end
96
+ =end
97
+ end
@@ -1,6 +1,6 @@
1
- class City < ActiveRecord::Base
2
- belongs_to :country
3
- has_many :streets, dependent: :destroy
4
- attr_accessible :country_id, :name
5
- validates_presence_of :country_id, :name
6
- end
1
+ class City < ActiveRecord::Base
2
+ belongs_to :country
3
+ has_many :streets, dependent: :destroy
4
+ attr_accessible :country_id, :name
5
+ validates_presence_of :country_id, :name
6
+ end
@@ -1,4 +1,4 @@
1
- class Language < ActiveRecord::Base
2
- attr_accessible :name
3
- validates_presence_of :name
4
- end
1
+ class Language < ActiveRecord::Base
2
+ attr_accessible :name
3
+ validates_presence_of :name
4
+ end
@@ -1,5 +1,5 @@
1
- class Street < ActiveRecord::Base
2
- belongs_to :city
3
- attr_accessible :city_id, :name
4
- validates_presence_of :city_id, :name
5
- end
1
+ class Street < ActiveRecord::Base
2
+ belongs_to :city
3
+ attr_accessible :city_id, :name
4
+ validates_presence_of :city_id, :name
5
+ end