dry_crud 1.6.0 → 1.7.0

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.rdoc +25 -10
  2. data/Rakefile +30 -8
  3. data/VERSION +1 -1
  4. data/lib/generators/dry_crud/dry_crud_generator.rb +15 -2
  5. data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +18 -10
  6. data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +14 -11
  7. data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +71 -29
  8. data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +40 -3
  9. data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +8 -27
  10. data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +13 -6
  11. data/lib/generators/dry_crud/templates/app/views/crud/_form.html.erb +1 -1
  12. data/lib/generators/dry_crud/templates/app/views/crud/_form.html.haml +1 -1
  13. data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +4 -4
  14. data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.haml +5 -5
  15. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +433 -0
  16. data/lib/generators/dry_crud/templates/spec/helpers/crud_helper_spec.rb +146 -0
  17. data/lib/generators/dry_crud/templates/spec/helpers/list_helper_spec.rb +154 -0
  18. data/lib/generators/dry_crud/templates/spec/helpers/standard_form_builder_spec.rb +215 -0
  19. data/lib/generators/dry_crud/templates/spec/helpers/standard_helper_spec.rb +387 -0
  20. data/lib/generators/dry_crud/templates/spec/helpers/standard_table_builder_spec.rb +120 -0
  21. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +244 -0
  22. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +160 -0
  23. data/lib/generators/dry_crud/templates/test/crud_test_model.rb +45 -18
  24. data/lib/generators/dry_crud/templates/test/functional/crud_controller_test_helper.rb +19 -9
  25. data/lib/generators/dry_crud/templates/test/functional/crud_test_models_controller_test.rb +11 -14
  26. data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +26 -13
  27. data/lib/generators/dry_crud/templates/test/unit/helpers/list_helper_test.rb +0 -4
  28. data/lib/generators/dry_crud/templates/test/unit/helpers/standard_form_builder_test.rb +6 -0
  29. data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +9 -35
  30. data/lib/generators/dry_crud/templates/test/unit/helpers/standard_table_builder_test.rb +5 -4
  31. data/test/templates/Gemfile +3 -1
  32. data/test/templates/app/controllers/people_controller.rb +1 -1
  33. data/test/templates/app/controllers/vips_controller.rb +1 -1
  34. data/test/templates/app/models/city.rb +1 -1
  35. data/test/templates/app/views/admin/cities/_form.html.erb +1 -1
  36. data/test/templates/app/views/admin/cities/_form.html.haml +1 -1
  37. data/test/templates/app/views/admin/countries/_list.html.erb +3 -4
  38. data/test/templates/app/views/admin/countries/_list.html.haml +3 -4
  39. data/test/templates/app/views/ajax/_form.html.erb +1 -1
  40. data/test/templates/app/views/ajax/_form.html.haml +1 -1
  41. data/test/templates/spec/controllers/admin/cities_controller_spec.rb +74 -0
  42. data/test/templates/spec/controllers/admin/countries_controller_spec.rb +56 -0
  43. data/test/templates/spec/controllers/people_controller_spec.rb +80 -0
  44. data/test/templates/spec/routing/cities_routing_spec.rb +11 -0
  45. data/test/templates/spec/routing/countries_routing_spec.rb +11 -0
  46. data/test/templates/test/functional/admin/cities_controller_test.rb +1 -1
  47. data/test/templates/test/functional/admin/countries_controller_test.rb +1 -1
  48. data/test/templates/test/functional/people_controller_test.rb +3 -3
  49. metadata +18 -7
@@ -4,11 +4,6 @@ require 'custom_assertions'
4
4
 
5
5
  class CrudHelperTest < ActionView::TestCase
6
6
 
7
- REGEXP_ROWS = /<tr.+?<\/tr>/m
8
- REGEXP_HEADERS = /<th.+?<\/th>/m
9
- REGEXP_SORT_HEADERS = /<th><a .*?sort_dir=asc.*?>.*?<\/a><\/th>/m
10
- REGEXP_ACTION_CELL = /<td class=\"action\"><a href.+?<\/a><\/td>/m
11
-
12
7
  include CustomAssertions
13
8
  include StandardHelper
14
9
  include ListHelper
@@ -28,7 +23,7 @@ class CrudHelperTest < ActionView::TestCase
28
23
 
29
24
  assert_count 7, REGEXP_ROWS, t
30
25
  assert_count 13, REGEXP_SORT_HEADERS, t
31
- assert_count 18, REGEXP_ACTION_CELL, t # show, edit, delete links
26
+ assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
32
27
  end
33
28
 
34
29
  test "custom crud table with attributes" do
@@ -40,7 +35,7 @@ class CrudHelperTest < ActionView::TestCase
40
35
 
41
36
  assert_count 7, REGEXP_ROWS, t
42
37
  assert_count 3, REGEXP_SORT_HEADERS, t
43
- assert_count 18, REGEXP_ACTION_CELL, t # show, edit, delete links
38
+ assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
44
39
  end
45
40
 
46
41
  test "custom crud table with block" do
@@ -54,9 +49,9 @@ class CrudHelperTest < ActionView::TestCase
54
49
  end
55
50
 
56
51
  assert_count 7, REGEXP_ROWS, t
57
- assert_count 4, REGEXP_HEADERS, t
52
+ assert_count 6, REGEXP_HEADERS, t
58
53
  assert_count 6, /<span>.+?<\/span>/m, t
59
- assert_count 0, REGEXP_ACTION_CELL, t # no show, edit, delete links
54
+ assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
60
55
  end
61
56
 
62
57
  test "custom crud table with attributes and block" do
@@ -69,15 +64,16 @@ class CrudHelperTest < ActionView::TestCase
69
64
  end
70
65
 
71
66
  assert_count 7, REGEXP_ROWS, t
72
- assert_count 4, REGEXP_HEADERS, t
67
+ assert_count 3, REGEXP_SORT_HEADERS, t
68
+ assert_count 6, REGEXP_HEADERS, t
73
69
  assert_count 6, /<span>.+?<\/span>/m, t
74
- assert_count 0, REGEXP_ACTION_CELL, t # no show, edit, delete links
70
+ assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
75
71
  end
76
72
 
77
73
 
78
- test "crud form" do
74
+ test "entry form" do
79
75
  f = with_test_routing do
80
- capture { crud_form }
76
+ capture { entry_form }
81
77
  end
82
78
 
83
79
  assert_match /form .*?action="\/crud_test_models\/#{entry.id}"/, f
@@ -90,8 +86,25 @@ class CrudHelperTest < ActionView::TestCase
90
86
  assert_match /input .*?name="crud_test_model\[human\]" .*?type="checkbox"/, f
91
87
  assert_match /select .*?name="crud_test_model\[companion_id\]"/, f
92
88
  assert_match /textarea .*?name="crud_test_model\[remarks\]"/, f
89
+ assert_match /a .*href="\/crud_test_models\/#{entry.id}\?returning=true".*>Cancel<\/a>/, f
93
90
  end
94
91
 
92
+ test "crud form" do
93
+ e = crud_test_models('AAAAA')
94
+ f = with_test_routing do
95
+ f = capture { crud_form(e, :name, :children, :birthdate, :human, :cancel_url => '/somewhere', :class => 'special') }
96
+ end
97
+
98
+ assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
99
+ assert_match /input .*?name="_method" .*?type="hidden" .*?value="put"/, f
100
+ assert_match /input .*?name="crud_test_model\[name\]" .*?type="text" .*?value="AAAAA"/, f
101
+ assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
102
+ assert_match /input .*?name="crud_test_model\[children\]" .*?type="number" .*?value=\"9\"/, f
103
+ assert_match /input .*?name="crud_test_model\[human\]" .*?type="checkbox"/, f
104
+ assert_match /button .*?type="submit">Save<\/button>/, f
105
+ assert_match /a .*href="\/somewhere".*>Cancel<\/a>/, f
106
+ end
107
+
95
108
  def entry
96
109
  @entry ||= CrudTestModel.first
97
110
  end
@@ -4,10 +4,6 @@ require 'custom_assertions'
4
4
 
5
5
  class ListHelperTest < ActionView::TestCase
6
6
 
7
- REGEXP_ROWS = /<tr.+?<\/tr>/m
8
- REGEXP_HEADERS = /<th.+?<\/th>/m
9
- REGEXP_SORT_HEADERS = /<th><a .*?sort_dir=asc.*?>.*?<\/a><\/th>/m
10
-
11
7
  include StandardHelper
12
8
  include CrudTestHelper
13
9
  include CustomAssertions
@@ -78,6 +78,12 @@ class StandardFormBuilderTest < ActionView::TestCase
78
78
  assert !result.include?(StandardFormBuilder::REQUIRED_MARK)
79
79
  end
80
80
 
81
+ test "labeld_input_field adds help text" do
82
+ result = form.labeled_input_field(:name, :help => 'Some Help')
83
+ assert result.include?(form.help_block('Some Help'))
84
+ assert result.include?(StandardFormBuilder::REQUIRED_MARK)
85
+ end
86
+
81
87
  test "belongs_to_field has all options by default" do
82
88
  f = form.belongs_to_field(:companion_id)
83
89
  assert_equal 7, f.scan('</option>').size
@@ -51,9 +51,9 @@ class StandardHelperTest < ActionView::TestCase
51
51
  end
52
52
 
53
53
  test "format Floats" do
54
- assert_equal "1.00", f(1.0)
55
- assert_equal "1.20", f(1.2)
56
- assert_equal "3.14", f(3.14159)
54
+ assert_equal "1.000", f(1.0)
55
+ assert_equal "1.200", f(1.2)
56
+ assert_equal "3.142", f(3.14159)
57
57
  end
58
58
 
59
59
  test "format Booleans" do
@@ -73,7 +73,7 @@ class StandardHelperTest < ActionView::TestCase
73
73
  end
74
74
 
75
75
  test "format attr with fallthrough to f" do
76
- assert_equal "12.23", format_attr("12.23424", :to_f)
76
+ assert_equal "12.234", format_attr("12.23424", :to_f)
77
77
  end
78
78
 
79
79
  test "format attr with custom format_string_size method" do
@@ -109,15 +109,15 @@ class StandardHelperTest < ActionView::TestCase
109
109
 
110
110
  test "format float column" do
111
111
  m = crud_test_models(:AAAAA)
112
- assert_equal '1.10', format_type(m, :rating)
112
+ assert_equal '1.100', format_type(m, :rating)
113
113
 
114
114
  m.rating = 3.145001 # you never know with these floats..
115
- assert_equal '3.15', format_type(m, :rating)
115
+ assert_equal '3.145', format_type(m, :rating)
116
116
  end
117
117
 
118
118
  test "format decimal column" do
119
119
  m = crud_test_models(:AAAAA)
120
- assert_equal '10000000.10', format_type(m, :income)
120
+ assert_equal '10,000,000.100', format_type(m, :income)
121
121
  end
122
122
 
123
123
  test "format date column" do
@@ -210,34 +210,11 @@ class StandardHelperTest < ActionView::TestCase
210
210
  test "standard form for existing entry" do
211
211
  e = crud_test_models('AAAAA')
212
212
  f = with_test_routing do
213
- f = capture { standard_form(e, :name, :children, :birthdate, :human, :class => 'special') }
213
+ f = capture { standard_form(e, :class => 'special') {|f|} }
214
214
  end
215
215
 
216
216
  assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
217
217
  assert_match /input .*?name="_method" .*?type="hidden" .*?value="put"/, f
218
- assert_match /input .*?name="crud_test_model\[name\]" .*?type="text" .*?value="AAAAA"/, f
219
- assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
220
- assert_match /option selected="selected" value="1910">1910<\/option>/, f
221
- assert_match /option selected="selected" value="1">January<\/option>/, f
222
- assert_match /option selected="selected" value="1">1<\/option>/, f
223
- assert_match /input .*?name="crud_test_model\[children\]" .*?type="number" .*?value=\"9\"/, f
224
- assert_match /input .*?name="crud_test_model\[human\]" .*?type="checkbox"/, f
225
- assert_match /button .*?type="submit">Save<\/button>/, f
226
- end
227
-
228
- test "standard form for new entry" do
229
- e = CrudTestModel.new
230
- f = with_test_routing do
231
- f = capture { standard_form(e, :name, :children, :birthdate, :human, :html => {:class => 'special'}) }
232
- end
233
-
234
- assert_match /form .*?action="\/crud_test_models" .?class="special form-horizontal" .*?method="post"/, f
235
- assert_match /input .*?name="crud_test_model\[name\]" .*?type="text"/, f
236
- assert_no_match /input .*?name="crud_test_model\[name\]" .*?type="text" .*?value=/, f
237
- assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
238
- assert_match /input .*?name="crud_test_model\[children\]" .*?type="number"/, f
239
- assert_no_match /input .*?name="crud_test_model\[children\]" .*?type="text" .*?value=/, f
240
- assert_match /button .*?type="submit">Save<\/button>/, f
241
218
  end
242
219
 
243
220
  test "standard form with errors" do
@@ -246,7 +223,7 @@ class StandardHelperTest < ActionView::TestCase
246
223
  assert !e.valid?
247
224
 
248
225
  f = with_test_routing do
249
- f = capture { standard_form(e, :name, :children, :birthdate, :human) }
226
+ f = capture { standard_form(e) {|f| f.labeled_input_fields(:name, :birthdate) } }
250
227
  end
251
228
 
252
229
  assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
@@ -257,9 +234,6 @@ class StandardHelperTest < ActionView::TestCase
257
234
  assert_match /option selected="selected" value="1910">1910<\/option>/, f
258
235
  assert_match /option selected="selected" value="1">January<\/option>/, f
259
236
  assert_match /option selected="selected" value="1">1<\/option>/, f
260
- assert_match /input .*?name="crud_test_model\[children\]" .*?type="number" .*?value=\"9\"/, f
261
- assert_match /input .*?name="crud_test_model\[human\]" .*?type="checkbox"/, f
262
- assert_match /button .*?type="submit">Save<\/button>/, f
263
237
  end
264
238
 
265
239
  test "translate inheritable lookup" do
@@ -5,10 +5,11 @@ class StandardTableBuilderTest < ActionView::TestCase
5
5
  # set dummy helper class for ActionView::TestCase
6
6
  self.helper_class = StandardHelper
7
7
 
8
- attr_reader :table
8
+ attr_reader :table, :entries
9
9
 
10
10
  def setup
11
- @table = StandardTableBuilder.new(["foo", "bahr"], self)
11
+ @entries = %w(foo bahr)
12
+ @table = StandardTableBuilder.new(entries, self)
12
13
  end
13
14
 
14
15
  def format_size(obj)
@@ -28,7 +29,7 @@ class StandardTableBuilderTest < ActionView::TestCase
28
29
 
29
30
  dom = '<tr><td>FOO</td><td>3 chars</td></tr>'
30
31
 
31
- assert_dom_equal dom, table.send(:html_row, "foo")
32
+ assert_dom_equal dom, table.send(:html_row, entries.first)
32
33
  end
33
34
 
34
35
  test "custom row" do
@@ -36,7 +37,7 @@ class StandardTableBuilderTest < ActionView::TestCase
36
37
 
37
38
  dom = '<tr><td class="hula">Weights 3 kg</td></tr>'
38
39
 
39
- assert_dom_equal dom, table.send(:html_row, "foo")
40
+ assert_dom_equal dom, table.send(:html_row, entries.first)
40
41
  end
41
42
 
42
43
  test "attr col output" do
@@ -18,6 +18,8 @@ gem 'haml'
18
18
 
19
19
  gem 'kaminari'
20
20
 
21
+ gem 'rspec-rails'
22
+
21
23
  # Gems used only for assets and not required
22
24
  # in production environments by default.
23
25
  group :assets do
@@ -25,7 +27,7 @@ group :assets do
25
27
  gem 'coffee-rails' #, '~> 3.2.1'
26
28
  gem 'uglifier' #, '>= 1.0.3'
27
29
  gem 'bootstrap-sass-rails'
28
- #gem 'therubyracer'
30
+ gem 'therubyracer', :require => RUBY_PLATFORM.include?('linux') && 'v8'
29
31
  end
30
32
 
31
33
  gem 'jquery-rails'
@@ -4,7 +4,7 @@ class PeopleController < AjaxController
4
4
 
5
5
  self.sort_mappings = {:city_id => 'cities.name'}
6
6
 
7
- protected
7
+ private
8
8
 
9
9
  def list_entries
10
10
  super.includes(:city => :country).order('people.name, countries.code, cities.name')
@@ -4,7 +4,7 @@ class VipsController < ListController
4
4
 
5
5
  self.sort_mappings = {:city_id => 'cities.name'}
6
6
 
7
- protected
7
+ private
8
8
 
9
9
  class << self
10
10
  def model_class
@@ -16,7 +16,7 @@ class City < ActiveRecord::Base
16
16
  "#{name} (#{country.code})"
17
17
  end
18
18
 
19
- protected
19
+ private
20
20
 
21
21
  def protect_with_inhabitants
22
22
  if people.exists?
@@ -1,5 +1,5 @@
1
1
  <% remote ||= false %>
2
- <%= crud_form :remote => remote do |f| %>
2
+ <%= entry_form :remote => remote do |f| %>
3
3
  <%= f.labeled(:name, 'Called') do %>
4
4
  <%= f.input_field :name %>
5
5
  <% end %>
@@ -1,5 +1,5 @@
1
1
  - remote ||= false
2
- = crud_form :remote => remote do |f|
2
+ = entry_form :remote => remote do |f|
3
3
  = f.labeled(:name, 'Called') do
4
4
  = f.input_field :name
5
5
  = f.labeled_input_field :person_ids
@@ -1,5 +1,4 @@
1
- <%= crud_table :name, :code do |t|
2
- action_col_show(t) {|e| admin_country_cities_path(e) }
3
- action_col_edit(t)
4
- action_col_destroy(t)
1
+ <%= crud_table do |t|
2
+ col_show(t, :name) {|e| admin_country_cities_path(e) }
3
+ t.sortable_attr(:code)
5
4
  end %>
@@ -1,4 +1,3 @@
1
- = crud_table :name, :code do |t|
2
- - action_col_show(t) {|e| admin_country_cities_path(e) }
3
- - action_col_edit(t)
4
- - action_col_destroy(t)
1
+ = crud_table do |t|
2
+ - col_show(t, :name) {|e| admin_country_cities_path(e) }
3
+ - t.sortable_attr(:code)
@@ -1,2 +1,2 @@
1
1
  <% remote ||= false %>
2
- <%= crud_form :remote => remote %>
2
+ <%= entry_form :remote => remote %>
@@ -1,2 +1,2 @@
1
1
  - remote ||= false
2
- = crud_form :remote => remote
2
+ = entry_form :remote => remote
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::CitiesController do
4
+
5
+ fixtures :all
6
+
7
+ include_examples 'crud controller', {}
8
+
9
+ let(:test_entry) { cities(:rj) }
10
+ let(:test_entry_attrs) { {:name => 'Rejkiavik'} }
11
+ alias_method :new_entry_attrs, :test_entry_attrs
12
+ alias_method :edit_entry_attrs, :test_entry_attrs
13
+
14
+ it "should load fixtures" do
15
+ City.count.should == 3
16
+ end
17
+
18
+ describe_action :get, :index do
19
+ it "should be ordered by default scope" do
20
+ entries == test_entry.country.cities.order('countries.code, cities.name')
21
+ end
22
+
23
+ it "should set parents" do
24
+ controller.send(:parents).should == [:admin, test_entry.country]
25
+ end
26
+
27
+ it "should set parent variable" do
28
+ assigns(:country).should == test_entry.country
29
+ end
30
+
31
+ it "should use correct model_scope" do
32
+ controller.send(:model_scope).should == test_entry.country.cities
33
+ end
34
+
35
+ it "should have correct path args" do
36
+ controller.send(:path_args, 2).should == [:admin, test_entry.country, 2]
37
+ end
38
+ end
39
+
40
+ describe_action :get, :show, :id => true do
41
+ it "should set parents" do
42
+ controller.send(:parents).should == [:admin, test_entry.country]
43
+ end
44
+
45
+ it "should set parent variable" do
46
+ assigns(:country).should == test_entry.country
47
+ end
48
+ end
49
+
50
+ describe_action :post, :create do
51
+ it "should set parent" do
52
+ entry.country.should == test_entry.country
53
+ end
54
+ end
55
+
56
+ describe_action :delete, :destroy, :id => true do
57
+ context "with inhabitants" do
58
+ let(:test_entry) { cities(:ny) }
59
+
60
+ it "should not remove city from database", :perform_request => false do
61
+ expect { perform_request }.to change { City.count }.by(0)
62
+ end
63
+
64
+ it "should redirect to referer", :perform_request => false do
65
+ ref = @request.env["HTTP_REFERER"] = admin_country_city_url(test_entry.country, test_entry)
66
+ perform_request
67
+ should redirect_to(ref)
68
+ end
69
+
70
+ it_should_have_flash(:alert)
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::CountriesController do
4
+
5
+ fixtures :all
6
+
7
+ include_examples 'crud controller', :skip => %w(show html plain)
8
+
9
+ let(:test_entry) { countries(:usa) }
10
+ let(:test_entry_attrs) { {:name => 'United States of America', :code => 'US'} }
11
+ alias_method :new_entry_attrs, :test_entry_attrs
12
+ alias_method :edit_entry_attrs, :test_entry_attrs
13
+
14
+ it "should load fixtures" do
15
+ Country.count.should == 3
16
+ end
17
+
18
+ describe_action :get, :index do
19
+ it "should be ordered by default scope" do
20
+ entries == Country.order(:name)
21
+ end
22
+
23
+ it "should set parents" do
24
+ controller.send(:parents).should == [:admin]
25
+ end
26
+
27
+ it "should set nil parent" do
28
+ controller.send(:parent).should be_nil
29
+ end
30
+
31
+ it "should use correct model_scope" do
32
+ controller.send(:model_scope).should == Country.scoped
33
+ end
34
+
35
+ it "should have correct path args" do
36
+ controller.send(:path_args, 2).should == [:admin, 2]
37
+ end
38
+ end
39
+
40
+ describe_action :get, :show do
41
+ let(:params) { {:id => test_entry.id} }
42
+ it_should_redirect_to_index
43
+ end
44
+
45
+ end
46
+
47
+ class Admin::CountriesControllerTest < ActionController::TestCase
48
+
49
+ include CrudControllerTestHelper
50
+
51
+ def test_show
52
+ get :show, test_params(:id => test_entry.id)
53
+ assert_redirected_to_index
54
+ end
55
+
56
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe PeopleController do
4
+
5
+ fixtures :all
6
+
7
+ render_views
8
+
9
+ include_examples 'crud controller', {}
10
+
11
+ let(:test_entry) { people(:john) }
12
+ let(:test_entry_attrs) { {:name => 'Fischers Fritz',
13
+ :children => 2,
14
+ :income => 120,
15
+ :city_id => cities(:rj).id} }
16
+ alias_method :new_entry_attrs, :test_entry_attrs
17
+ alias_method :edit_entry_attrs, :test_entry_attrs
18
+
19
+ it "should load fixtures" do
20
+ Person.count.should == 2
21
+ end
22
+
23
+ describe_action :get, :index do
24
+ it "should be ordered by default scope" do
25
+ entries == Person.includes(:city => :country).order('people.name, countries.code, cities.name')
26
+ end
27
+
28
+ it "should set parents" do
29
+ controller.send(:parents).should == []
30
+ end
31
+
32
+ it "should set nil parent" do
33
+ controller.send(:parent).should be_nil
34
+ end
35
+
36
+ it "should use correct model_scope" do
37
+ controller.send(:model_scope).should == Person.scoped
38
+ end
39
+
40
+ it "should have correct path args" do
41
+ controller.send(:path_args, 2).should == [2]
42
+ end
43
+ end
44
+
45
+ describe_action :get, :show, :id => true do
46
+ context ".js", :format => :js do
47
+ it_should_respond
48
+ it_should_render
49
+ its(:body) { should match(/\$\('#content'\)/) }
50
+ end
51
+ end
52
+
53
+ describe_action :get, :edit, :id => true do
54
+ context ".js", :format => :js do
55
+ it_should_respond
56
+ it_should_render
57
+ its(:body) { should match(/\$\('#content'\)/) }
58
+ end
59
+ end
60
+
61
+ describe_action :put, :update, :id => true do
62
+ context ".js", :format => :js do
63
+ context 'with valid params' do
64
+ let(:params) { {:person => {:name => 'New Name'} } }
65
+
66
+ it_should_respond
67
+ it_should_render
68
+ its(:body) { should match(/\$\('#content'\)/) }
69
+ end
70
+
71
+ context "with invalid params" do
72
+ let(:params) { {:person => {:name => ' '} } }
73
+
74
+ it_should_respond
75
+ it_should_render
76
+ its(:body) { should match(/alert/) }
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::CitiesController do
4
+ it "should route index" do
5
+ { :get => 'admin/countries/1/cities' }.should route_to({:controller => 'admin/cities', :action => 'index', :country_id => '1'})
6
+ end
7
+
8
+ it "should route show" do
9
+ { :get => 'admin/countries/2/cities/1' }.should route_to({:controller => 'admin/cities', :action => 'show', :country_id => '2', :id => '1'})
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::CountriesController do
4
+ it "should route index" do
5
+ { :get => 'admin/countries' }.should route_to({:controller => 'admin/countries', :action => 'index'})
6
+ end
7
+
8
+ it "should route show" do
9
+ { :get => 'admin/countries/1' }.should route_to({:controller => 'admin/countries', :action => 'show', :id => '1'})
10
+ end
11
+ end
@@ -46,7 +46,7 @@ class Admin::CitiesControllerTest < ActionController::TestCase
46
46
  assert_present flash[:alert]
47
47
  end
48
48
 
49
- protected
49
+ private
50
50
 
51
51
  def test_entry
52
52
  cities(:rj)
@@ -25,7 +25,7 @@ class Admin::CountriesControllerTest < ActionController::TestCase
25
25
  assert_redirected_to_index
26
26
  end
27
27
 
28
- protected
28
+ private
29
29
 
30
30
  def assert_redirected_to_show2(entry)
31
31
  assert_redirected_to_index
@@ -54,9 +54,9 @@ class PeopleControllerTest < ActionController::TestCase
54
54
  assert_template 'update'
55
55
  assert_match /alert/, response.body
56
56
  end
57
-
58
- protected
59
-
57
+
58
+ private
59
+
60
60
  def test_entry
61
61
  people(:john)
62
62
  end