dry_crud 1.7.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +126 -87
  4. data/VERSION +1 -1
  5. data/lib/generators/dry_crud/dry_crud_generator.rb +42 -22
  6. data/lib/generators/dry_crud/templates/INSTALL +5 -5
  7. data/lib/generators/dry_crud/templates/app/assets/stylesheets/crud.scss +0 -20
  8. data/lib/generators/dry_crud/templates/app/assets/stylesheets/sample.scss +24 -4
  9. data/lib/generators/dry_crud/templates/app/controllers/crud/generic_model.rb +89 -0
  10. data/lib/generators/dry_crud/templates/app/controllers/crud/nestable.rb +70 -0
  11. data/lib/generators/dry_crud/templates/app/controllers/crud/rememberable.rb +64 -0
  12. data/lib/generators/dry_crud/templates/app/controllers/crud/render_callbacks.rb +46 -0
  13. data/lib/generators/dry_crud/templates/app/controllers/crud/responder.rb +31 -0
  14. data/lib/generators/dry_crud/templates/app/controllers/crud/searchable.rb +55 -0
  15. data/lib/generators/dry_crud/templates/app/controllers/crud/sortable.rb +63 -0
  16. data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +66 -69
  17. data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +23 -326
  18. data/lib/generators/dry_crud/templates/app/helpers/actions_helper.rb +64 -0
  19. data/lib/generators/dry_crud/templates/app/helpers/crud/form_builder.rb +331 -0
  20. data/lib/generators/dry_crud/templates/app/helpers/crud/table_builder.rb +280 -0
  21. data/lib/generators/dry_crud/templates/app/helpers/form_helper.rb +52 -0
  22. data/lib/generators/dry_crud/templates/app/helpers/format_helper.rb +164 -0
  23. data/lib/generators/dry_crud/templates/app/helpers/i18n_helper.rb +85 -0
  24. data/lib/generators/dry_crud/templates/app/helpers/table_helper.rb +83 -0
  25. data/lib/generators/dry_crud/templates/app/helpers/utility_helper.rb +84 -0
  26. data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.erb +3 -3
  27. data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.haml +3 -3
  28. data/lib/generators/dry_crud/templates/app/views/crud/_actions_index.html.erb +1 -1
  29. data/lib/generators/dry_crud/templates/app/views/crud/_actions_index.html.haml +1 -1
  30. data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.erb +3 -3
  31. data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.haml +3 -3
  32. data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.erb +1 -1
  33. data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.haml +1 -1
  34. data/lib/generators/dry_crud/templates/app/views/crud/_form.html.erb +1 -1
  35. data/lib/generators/dry_crud/templates/app/views/crud/_form.html.haml +1 -1
  36. data/lib/generators/dry_crud/templates/app/views/crud/edit.html.erb +1 -1
  37. data/lib/generators/dry_crud/templates/app/views/crud/edit.html.haml +1 -1
  38. data/lib/generators/dry_crud/templates/app/views/crud/new.html.erb +2 -2
  39. data/lib/generators/dry_crud/templates/app/views/crud/new.html.haml +2 -2
  40. data/lib/generators/dry_crud/templates/app/views/crud/show.html.erb +1 -1
  41. data/lib/generators/dry_crud/templates/app/views/crud/show.html.haml +1 -1
  42. data/lib/generators/dry_crud/templates/app/views/layouts/_flash.html.haml +1 -1
  43. data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.erb +1 -1
  44. data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.haml +1 -1
  45. data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +15 -7
  46. data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.haml +18 -8
  47. data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +3 -3
  48. data/lib/generators/dry_crud/templates/app/views/list/_search.html.haml +3 -3
  49. data/lib/generators/dry_crud/templates/app/views/list/index.html.erb +1 -1
  50. data/lib/generators/dry_crud/templates/app/views/list/index.html.haml +1 -1
  51. data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +1 -1
  52. data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.haml +1 -1
  53. data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.erb +2 -4
  54. data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.haml +2 -3
  55. data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +5 -1
  56. data/lib/generators/dry_crud/templates/config/locales/crud.de.yml +64 -0
  57. data/lib/generators/dry_crud/templates/config/locales/{en_crud.yml → crud.en.yml} +2 -2
  58. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +241 -231
  59. data/lib/generators/dry_crud/templates/spec/helpers/crud/form_builder_spec.rb +226 -0
  60. data/lib/generators/dry_crud/templates/spec/helpers/{standard_table_builder_spec.rb → crud/table_builder_spec.rb} +36 -34
  61. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +238 -0
  62. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +244 -0
  63. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +132 -0
  64. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +265 -0
  65. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +74 -0
  66. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +185 -100
  67. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +58 -49
  68. data/lib/generators/dry_crud/templates/test/{functional → controllers}/crud_test_models_controller_test.rb +112 -91
  69. data/lib/generators/dry_crud/templates/test/{unit/helpers/standard_form_builder_test.rb → helpers/crud/form_builder_test.rb} +79 -62
  70. data/lib/generators/dry_crud/templates/test/{unit/helpers/standard_table_builder_test.rb → helpers/crud/table_builder_test.rb} +31 -28
  71. data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +85 -0
  72. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +129 -0
  73. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +163 -0
  74. data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +79 -0
  75. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +217 -0
  76. data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +63 -0
  77. data/lib/generators/dry_crud/templates/test/{functional → support}/crud_controller_test_helper.rb +70 -59
  78. data/lib/generators/dry_crud/templates/test/{crud_test_model.rb → support/crud_test_model.rb} +107 -75
  79. data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +83 -0
  80. metadata +83 -146
  81. data/Rakefile +0 -211
  82. data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +0 -168
  83. data/lib/generators/dry_crud/templates/app/helpers/list_helper.rb +0 -27
  84. data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +0 -261
  85. data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +0 -304
  86. data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +0 -178
  87. data/lib/generators/dry_crud/templates/spec/helpers/crud_helper_spec.rb +0 -146
  88. data/lib/generators/dry_crud/templates/spec/helpers/list_helper_spec.rb +0 -154
  89. data/lib/generators/dry_crud/templates/spec/helpers/standard_form_builder_spec.rb +0 -215
  90. data/lib/generators/dry_crud/templates/spec/helpers/standard_helper_spec.rb +0 -387
  91. data/lib/generators/dry_crud/templates/test/custom_assertions.rb +0 -78
  92. data/lib/generators/dry_crud/templates/test/unit/custom_assertions_test.rb +0 -117
  93. data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +0 -111
  94. data/lib/generators/dry_crud/templates/test/unit/helpers/list_helper_test.rb +0 -123
  95. data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +0 -281
  96. data/test/templates/Gemfile +0 -46
  97. data/test/templates/app/controllers/admin/cities_controller.rb +0 -7
  98. data/test/templates/app/controllers/admin/countries_controller.rb +0 -13
  99. data/test/templates/app/controllers/ajax_controller.rb +0 -9
  100. data/test/templates/app/controllers/people_controller.rb +0 -13
  101. data/test/templates/app/controllers/vips_controller.rb +0 -19
  102. data/test/templates/app/helpers/cities_helper.rb +0 -9
  103. data/test/templates/app/helpers/people_helper.rb +0 -8
  104. data/test/templates/app/models/city.rb +0 -28
  105. data/test/templates/app/models/country.rb +0 -16
  106. data/test/templates/app/models/person.rb +0 -12
  107. data/test/templates/app/views/admin/cities/_actions_index.html.erb +0 -2
  108. data/test/templates/app/views/admin/cities/_actions_index.html.haml +0 -2
  109. data/test/templates/app/views/admin/cities/_attrs.html.erb +0 -1
  110. data/test/templates/app/views/admin/cities/_attrs.html.haml +0 -1
  111. data/test/templates/app/views/admin/cities/_form.html.erb +0 -7
  112. data/test/templates/app/views/admin/cities/_form.html.haml +0 -5
  113. data/test/templates/app/views/admin/cities/_hello.html.erb +0 -1
  114. data/test/templates/app/views/admin/cities/_hello.html.haml +0 -1
  115. data/test/templates/app/views/admin/cities/_list.html.erb +0 -3
  116. data/test/templates/app/views/admin/cities/_list.html.haml +0 -3
  117. data/test/templates/app/views/admin/countries/_list.html.erb +0 -4
  118. data/test/templates/app/views/admin/countries/_list.html.haml +0 -3
  119. data/test/templates/app/views/ajax/_actions_index.html.erb +0 -8
  120. data/test/templates/app/views/ajax/_actions_index.html.haml +0 -8
  121. data/test/templates/app/views/ajax/_actions_show.html.erb +0 -4
  122. data/test/templates/app/views/ajax/_actions_show.html.haml +0 -4
  123. data/test/templates/app/views/ajax/_form.html.erb +0 -2
  124. data/test/templates/app/views/ajax/_form.html.haml +0 -2
  125. data/test/templates/app/views/ajax/_hello.html.erb +0 -1
  126. data/test/templates/app/views/ajax/_hello.html.haml +0 -1
  127. data/test/templates/app/views/ajax/ajax.js.erb +0 -1
  128. data/test/templates/app/views/ajax/ajax.js.haml +0 -1
  129. data/test/templates/app/views/ajax/edit.js.erb +0 -1
  130. data/test/templates/app/views/ajax/edit.js.haml +0 -1
  131. data/test/templates/app/views/ajax/show.js.erb +0 -1
  132. data/test/templates/app/views/ajax/show.js.haml +0 -1
  133. data/test/templates/app/views/ajax/update.js.erb +0 -5
  134. data/test/templates/app/views/ajax/update.js.haml +0 -5
  135. data/test/templates/app/views/layouts/_nav.html.erb +0 -6
  136. data/test/templates/app/views/layouts/_nav.html.haml +0 -5
  137. data/test/templates/app/views/layouts/bootstrap.html.erb +0 -68
  138. data/test/templates/app/views/layouts/bootstrap.html.haml +0 -49
  139. data/test/templates/app/views/people/_attrs.html.erb +0 -5
  140. data/test/templates/app/views/people/_attrs.html.haml +0 -4
  141. data/test/templates/app/views/people/_list.html.erb +0 -1
  142. data/test/templates/app/views/people/_list.html.haml +0 -1
  143. data/test/templates/config/database.yml +0 -21
  144. data/test/templates/config/locales/en_cities.yml +0 -56
  145. data/test/templates/config/routes.rb +0 -32
  146. data/test/templates/db/migrate/20100511174904_create_people_and_cities.rb +0 -26
  147. data/test/templates/db/seeds.rb +0 -74
  148. data/test/templates/spec/controllers/admin/cities_controller_spec.rb +0 -74
  149. data/test/templates/spec/controllers/admin/countries_controller_spec.rb +0 -56
  150. data/test/templates/spec/controllers/people_controller_spec.rb +0 -80
  151. data/test/templates/spec/routing/cities_routing_spec.rb +0 -11
  152. data/test/templates/spec/routing/countries_routing_spec.rb +0 -11
  153. data/test/templates/test/fixtures/cities.yml +0 -11
  154. data/test/templates/test/fixtures/countries.yml +0 -11
  155. data/test/templates/test/fixtures/people.yml +0 -14
  156. data/test/templates/test/functional/admin/cities_controller_test.rb +0 -59
  157. data/test/templates/test/functional/admin/countries_controller_test.rb +0 -42
  158. data/test/templates/test/functional/people_controller_test.rb +0 -68
@@ -1,146 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- describe CrudHelper do
5
-
6
- include StandardHelper
7
- include ListHelper
8
- include CrudTestHelper
9
-
10
-
11
- before(:all) do
12
- reset_db
13
- setup_db
14
- create_test_data
15
- end
16
-
17
- after(:all) { reset_db }
18
-
19
-
20
- describe "#crud_table" do
21
- let(:entries) { CrudTestModel.all }
22
-
23
- context "default" do
24
- subject do
25
- with_test_routing { crud_table }
26
- end
27
-
28
- it "has 7 rows" do
29
- subject.scan(REGEXP_ROWS).size.should == 7
30
- end
31
-
32
- it "has 13 sort headers" do
33
- subject.scan(REGEXP_SORT_HEADERS).size.should == 13
34
- end
35
-
36
- it "has 12 action cells" do
37
- subject.scan(REGEXP_ACTION_CELL).size.should == 12
38
- end
39
- end
40
-
41
- context "with custom attrs" do
42
- subject do
43
- with_test_routing { crud_table(:name, :children, :companion_id) }
44
- end
45
-
46
- it "has 3 sort headers" do
47
- subject.scan(REGEXP_SORT_HEADERS).size.should == 3
48
- end
49
- end
50
-
51
- context "with custom block" do
52
- subject do
53
- with_test_routing do
54
- crud_table do |t|
55
- t.attrs :name, :children, :companion_id
56
- t.col("head") {|e| content_tag :span, e.income.to_s }
57
- end
58
- end
59
- end
60
-
61
- it "has 4 headers" do
62
- subject.scan(REGEXP_HEADERS).size.should == 6
63
- end
64
-
65
- it "has 6 custom col spans" do
66
- subject.scan(/<span>.+?<\/span>/m).size.should == 6
67
- end
68
-
69
- it "has 12 action cells" do
70
- subject.scan(REGEXP_ACTION_CELL).size.should == 12
71
- end
72
- end
73
-
74
- context "with custom attributes and block" do
75
- subject do
76
- with_test_routing do
77
- crud_table(:name, :children, :companion_id) do |t|
78
- t.col("head") {|e| content_tag :span, e.income.to_s }
79
- end
80
- end
81
- end
82
-
83
- it "has 3 sort headers" do
84
- subject.scan(REGEXP_SORT_HEADERS).size.should == 3
85
- end
86
-
87
- it "has 6 custom col spans" do
88
- subject.scan(/<span>.+?<\/span>/m).size.should == 6
89
- end
90
-
91
- it "has 12 action cells" do
92
- subject.scan(REGEXP_ACTION_CELL).size.should == 12
93
- end
94
- end
95
- end
96
-
97
- describe "#entry_form" do
98
- let(:entry) { CrudTestModel.first }
99
- subject do
100
- with_test_routing { entry_form }
101
- end
102
-
103
- it { should match /form .*?action="\/crud_test_models\/#{entry.id}"/ }
104
- it { should match /input .*?name="crud_test_model\[name\]" .*?type="text"/ }
105
- it { should match /input .*?name="crud_test_model\[whatever\]" .*?type="text"/ }
106
- it { should match /input .*?name="crud_test_model\[children\]" .*?type="number"/ }
107
- it { should match /input .*?name="crud_test_model\[rating\]" .*?type="number"/ }
108
- it { should match /input .*?name="crud_test_model\[income\]" .*?type="number"/ }
109
- it { should match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/ }
110
- it { should match /input .*?name="crud_test_model\[human\]" .*?type="checkbox"/ }
111
- it { should match /select .*?name="crud_test_model\[companion_id\]"/ }
112
- it { should match /textarea .*?name="crud_test_model\[remarks\]"/ }
113
- it { should match(/a .*href="\/crud_test_models\/#{entry.id}\?returning=true".*>Cancel<\/a>/) }
114
- end
115
-
116
- describe "#crud_form" do
117
-
118
- context "for existing entry" do
119
- subject do
120
- with_test_routing do
121
- capture do
122
- crud_form(entry,
123
- :name, :children, :birthdate, :human,
124
- :cancel_url => "/somewhere",
125
- :html => {:class => 'special'})
126
- end
127
- end
128
- end
129
-
130
- let(:entry) { crud_test_models(:AAAAA) }
131
-
132
- it { should match(/form .*?action="\/crud_test_models\/#{entry.id}" .?class="special form-horizontal" .*?method="post"/) }
133
- it { should match(/input .*?name="_method" .*?type="hidden" .*?value="put"/) }
134
- it { should match(/input .*?name="crud_test_model\[name\]" .*?type="text" .*?value="AAAAA"/) }
135
- it { should match(/select .*?name="crud_test_model\[birthdate\(1i\)\]"/) }
136
- it { should match(/option selected="selected" value="1910">1910<\/option>/) }
137
- it { should match(/option selected="selected" value="1">January<\/option>/) }
138
- it { should match(/option selected="selected" value="1">1<\/option>/) }
139
- it { should match(/input .*?name="crud_test_model\[children\]" .*?type="number" .*?value=\"9\"/) }
140
- it { should match(/input .*?name="crud_test_model\[human\]" .*?type="checkbox"/) }
141
- it { should match(/button .*?type="submit">Save<\/button>/) }
142
- it { should match(/a .*href="\/somewhere".*>Cancel<\/a>/) }
143
- end
144
- end
145
-
146
- end
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ListHelper do
4
-
5
- include StandardHelper
6
- include CrudTestHelper
7
-
8
-
9
- before(:all) do
10
- reset_db
11
- setup_db
12
- create_test_data
13
- end
14
-
15
- after(:all) { reset_db }
16
-
17
- describe "#list_table" do
18
- let(:entries) { CrudTestModel.all }
19
-
20
- context "default" do
21
- subject do
22
- with_test_routing { list_table }
23
- end
24
-
25
- it "has 7 rows" do
26
- subject.scan(REGEXP_ROWS).size.should == 7
27
- end
28
-
29
- it "has 13 sortable headers" do
30
- subject.scan(REGEXP_SORT_HEADERS).size.should == 13
31
- end
32
- end
33
-
34
- context "with custom attributes" do
35
- subject do
36
- with_test_routing { list_table(:name, :children, :companion_id) }
37
- end
38
-
39
- it "has 7 rows" do
40
- subject.scan(REGEXP_ROWS).size.should == 7
41
- end
42
-
43
- it "has 3 sortable headers" do
44
- subject.scan(REGEXP_SORT_HEADERS).size.should == 3
45
- end
46
- end
47
-
48
- context "with custom block" do
49
- subject do
50
- with_test_routing do
51
- list_table do |t|
52
- t.attrs :name, :children, :companion_id
53
- t.col('head') {|e| content_tag(:span, e.income.to_s) }
54
- end
55
- end
56
- end
57
-
58
- it "has 7 rows" do
59
- subject.scan(REGEXP_ROWS).size.should == 7
60
- end
61
-
62
- it "has 4 headers" do
63
- subject.scan(REGEXP_HEADERS).size.should == 4
64
- end
65
-
66
- it "has 0 sortable headers" do
67
- subject.scan(REGEXP_SORT_HEADERS).size.should == 0
68
- end
69
-
70
- it "has 6 spans" do
71
- subject.scan(/<span>.+?<\/span>/).size.should == 6
72
- end
73
- end
74
-
75
- context "with custom attributes and block" do
76
- subject do
77
- with_test_routing do
78
- list_table(:name, :children, :companion_id) do |t|
79
- t.col('head') {|e| content_tag(:span, e.income.to_s) }
80
- end
81
- end
82
- end
83
-
84
- it "has 7 rows" do
85
- subject.scan(REGEXP_ROWS).size.should == 7
86
- end
87
-
88
- it "has 4 headers" do
89
- subject.scan(REGEXP_HEADERS).size.should == 4
90
- end
91
-
92
- it "has 3 sortable headers" do
93
- subject.scan(REGEXP_SORT_HEADERS).size.should == 3
94
- end
95
-
96
- it "has 6 spans" do
97
- subject.scan(/<span>.+?<\/span>/).size.should == 6
98
- end
99
- end
100
-
101
- context "with ascending sort params" do
102
- let(:params) { {:sort => 'children', :sort_dir => 'asc'} }
103
- subject do
104
- with_test_routing { list_table }
105
- end
106
-
107
- it "has 12 sortable headers" do
108
- subject.scan(REGEXP_SORT_HEADERS).size.should == 12
109
- end
110
-
111
- it "has 1 ascending sort headers" do
112
- subject.scan(/<th><a .*?sort_dir=desc.*?>Children<\/a> &darr;<\/th>/).size.should == 1
113
- end
114
- end
115
-
116
- context "with descending sort params" do
117
- let(:params) { {:sort => 'children', :sort_dir => 'desc'} }
118
- subject do
119
- with_test_routing { list_table }
120
- end
121
-
122
- it "has 12 sortable headers" do
123
- subject.scan(REGEXP_SORT_HEADERS).size.should == 12
124
- end
125
-
126
- it "has 1 descending sort headers" do
127
- subject.scan(/<th><a .*?sort_dir=asc.*?>Children<\/a> &uarr;<\/th>/).size.should == 1
128
- end
129
- end
130
-
131
- context "with custom column sort params" do
132
- let(:params) { {:sort => 'chatty', :sort_dir => 'asc'} }
133
- subject do
134
- with_test_routing { list_table(:name, :children, :chatty) }
135
- end
136
-
137
- it "has 2 sortable headers" do
138
- subject.scan(REGEXP_SORT_HEADERS).size.should == 2
139
- end
140
-
141
- it "has 1 ascending sort headers" do
142
- subject.scan(/<th><a .*?sort_dir=desc.*?>Chatty<\/a> &darr;<\/th>/).size.should == 1
143
- end
144
- end
145
- end
146
-
147
- describe "#default_attrs" do
148
- it "do not contain id" do
149
- default_attrs.should == [:name, :whatever, :children, :companion_id, :rating, :income,
150
- :birthdate, :gets_up_at, :last_seen, :human, :remarks,
151
- :created_at, :updated_at]
152
- end
153
- end
154
- end
@@ -1,215 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'StandardFormBuilder' do
4
-
5
- include StandardHelper
6
- include ListHelper
7
- include CrudTestHelper
8
-
9
- before(:all) do
10
- reset_db
11
- setup_db
12
- create_test_data
13
- end
14
-
15
- after(:all) { reset_db }
16
-
17
- let(:entry) { CrudTestModel.first }
18
- let(:form) { StandardFormBuilder.new(:entry, entry, self, {}, lambda {|form| form }) }
19
-
20
- describe "#input_field" do
21
-
22
- {:name => :string_field,
23
- :password => :password_field,
24
- :remarks => :text_area,
25
- :children => :integer_field,
26
- :human => :boolean_field,
27
- :birthdate => :date_field,
28
- :gets_up_at => :time_field,
29
- :companion_id => :belongs_to_field,
30
- :other_ids => :has_many_field,
31
- :more_ids => :has_many_field,
32
- }.each do |attr, method|
33
- it "dispatches #{attr} attr to #{method}" do
34
- form.should_receive(method).with(attr, {})
35
- form.input_field(attr)
36
- end
37
-
38
- it { form.input_field(attr).should be_html_safe }
39
- end
40
-
41
- end
42
-
43
- describe "#labeled_input_fields" do
44
- subject { form.labeled_input_fields(:name, :remarks, :children) }
45
-
46
- it { should be_html_safe }
47
- it { should include(form.input_field(:name)) }
48
- it { should include(form.input_field(:remarks)) }
49
- it { should include(form.input_field(:children)) }
50
- end
51
-
52
- describe "#labeled_input_field" do
53
- context "when required" do
54
- subject { form.labeled_input_field(:name) }
55
- it { should include(StandardFormBuilder::REQUIRED_MARK) }
56
- end
57
-
58
- context "when not required" do
59
- subject { form.labeled_input_field(:remarks) }
60
- it { should_not include(StandardFormBuilder::REQUIRED_MARK) }
61
- end
62
-
63
- context "with help text" do
64
- subject { form.labeled_input_field(:name, :help => 'Some Help') }
65
- it { should include(form.help_block('Some Help')) }
66
- end
67
- end
68
-
69
- describe "#belongs_to_field" do
70
- it "has all options by default" do
71
- f = form.belongs_to_field(:companion_id)
72
- f.scan('</option>').should have(7).items
73
- end
74
-
75
- it "with has options from :list option" do
76
- list = CrudTestModel.all
77
- f = form.belongs_to_field(:companion_id, :list => [list.first, list.second])
78
- f.scan('</option>').should have(3).items
79
- end
80
-
81
- it "with empty instance list has no select" do
82
- assign(:companions, [])
83
- @companions = []
84
- f = form.belongs_to_field(:companion_id)
85
- f.should match(/none available/m)
86
- f.scan('</option>').should have(0).items
87
- end
88
- end
89
-
90
- describe "#has_and_belongs_to_many_field" do
91
- let(:others) { OtherCrudTestModel.all[0..1] }
92
-
93
- it "has all options by default" do
94
- f = form.has_many_field(:other_ids)
95
- f.scan('</option>').should have(6).items
96
- end
97
-
98
- it "uses options from :list option if given" do
99
- f = form.has_many_field(:other_ids, :list => others)
100
- f.scan('</option>').should have(2).items
101
- end
102
-
103
- it "uses options form instance variable if given" do
104
- assign(:others, others)
105
- @others = others
106
- f = form.has_many_field(:other_ids)
107
- f.scan('</option>').should have(2).items
108
- end
109
-
110
- it "displays a message for an empty list" do
111
- @others = []
112
- f = form.has_many_field(:other_ids)
113
- f.should match /none available/m
114
- f.scan('</option>').should have(0).items
115
- end
116
- end
117
-
118
- describe "#string_field" do
119
- it "sets maxlength if attr has a limit" do
120
- form.string_field(:name).should match /maxlength="50"/
121
- end
122
- end
123
-
124
- describe "#label" do
125
- context "only with attr" do
126
- subject { form.label(:gugus_dada) }
127
-
128
- it { should be_html_safe }
129
- it "provides the same interface as rails" do
130
- should match /label [^>]*for.+Gugus dada/
131
- end
132
- end
133
-
134
- context "with attr and text" do
135
- subject { form.label(:gugus_dada, "hoho") }
136
-
137
- it { should be_html_safe }
138
- it "provides the same interface as rails" do
139
- should match /label [^>]*for.+hoho/
140
- end
141
- end
142
-
143
- end
144
-
145
- describe "#labeled" do
146
- context "in labeled_ method" do
147
- subject { form.labeled_string_field(:name) }
148
-
149
- it { should be_html_safe }
150
- it "provides the same interface as rails" do
151
- should match /label [^>]*for.+input/m
152
- end
153
- end
154
-
155
- context "with custom content in argument" do
156
- subject { form.labeled("gugus", "<input type='text' name='gugus' />".html_safe) }
157
-
158
- it { should be_html_safe }
159
- it { should match /label [^>]*for.+<input/m }
160
- end
161
-
162
- context "with custom content in block" do
163
- subject { form.labeled("gugus") { "<input type='text' name='gugus' />".html_safe } }
164
-
165
- it { should be_html_safe }
166
- it { should match /label [^>]*for.+<input/m }
167
- end
168
-
169
- context "with caption and content in argument" do
170
- subject { form.labeled("gugus", 'Caption', "<input type='text' name='gugus' />".html_safe) }
171
-
172
- it { should be_html_safe }
173
- it { should match /label [^>]*for.+>Caption<\/label>.*<input/m }
174
- end
175
-
176
- context "with caption and content in block" do
177
- subject { form.labeled("gugus", 'Caption') { "<input type='text' name='gugus' />".html_safe } }
178
-
179
- it { should be_html_safe }
180
- it { should match /label [^>]*for.+>Caption<\/label>.*<input/m }
181
- end
182
- end
183
-
184
- describe "#required_mark" do
185
- it "is shown for required attrs" do
186
- form.required_mark(:name).should == StandardFormBuilder::REQUIRED_MARK
187
- end
188
-
189
- it "is not shown for optional attrs" do
190
- form.required_mark(:rating).should be_empty
191
- end
192
-
193
- it "is not shown for non existing attrs" do
194
- form.required_mark(:not_existing).should be_empty
195
- end
196
- end
197
-
198
- it "handles missing methods" do
199
- expect { form.blabla }.to raise_error(NoMethodError)
200
- end
201
-
202
- context "#respond_to?" do
203
- it "returns false for non existing methods" do
204
- form.respond_to?(:blabla).should be_false
205
- end
206
-
207
- it "returns true for existing methods" do
208
- form.respond_to?(:text_field).should be_true
209
- end
210
-
211
- it "returns true for labeled_ methods" do
212
- form.respond_to?(:labeled_text_field).should be_true
213
- end
214
- end
215
- end