extjs-mvc 0.3.10 → 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +5 -173
  3. data/Rakefile +18 -20
  4. data/VERSION +1 -1
  5. data/bin/xmvc +13 -0
  6. data/lib/extjs-mvc/README +20 -0
  7. data/lib/extjs-mvc/builder.rb +83 -0
  8. data/lib/extjs-mvc/builders/all_builder.rb +15 -0
  9. data/lib/extjs-mvc/builders/app_builder.rb +36 -0
  10. data/lib/extjs-mvc/builders/base.rb +138 -0
  11. data/lib/extjs-mvc/builders/css_builder.rb +36 -0
  12. data/lib/extjs-mvc/builders/docs_builder.rb +20 -0
  13. data/lib/extjs-mvc/builders/mvc_builder.rb +33 -0
  14. data/lib/extjs-mvc/builders/plugin_builder.rb +53 -0
  15. data/lib/extjs-mvc/cli.rb +52 -0
  16. data/lib/extjs-mvc/generator.rb +79 -0
  17. data/lib/extjs-mvc/generators/app.rb +57 -0
  18. data/lib/extjs-mvc/generators/base.rb +53 -0
  19. data/lib/extjs-mvc/generators/controller.rb +41 -0
  20. data/lib/extjs-mvc/generators/model.rb +41 -0
  21. data/lib/extjs-mvc/generators/scaffold.rb +17 -0
  22. data/lib/extjs-mvc/generators/templates/Controller.js +17 -0
  23. data/lib/extjs-mvc/generators/templates/Model.js +9 -0
  24. data/lib/extjs-mvc/generators/templates/ModelSpec.js +12 -0
  25. data/lib/extjs-mvc/generators/templates/View.js +16 -0
  26. data/lib/extjs-mvc/generators/templates/_Action.js +7 -0
  27. data/lib/extjs-mvc/generators/templates/app/README.rdoc +152 -0
  28. data/lib/extjs-mvc/generators/templates/app/app/App.js +64 -0
  29. data/lib/extjs-mvc/generators/templates/app/app/controllers/ApplicationController.js +10 -0
  30. data/lib/extjs-mvc/generators/templates/app/app/controllers/HomeController.js +10 -0
  31. data/lib/extjs-mvc/generators/templates/app/app/views/home/Index.js +17 -0
  32. data/lib/extjs-mvc/generators/templates/app/app/views/layout/Menu.js +23 -0
  33. data/lib/extjs-mvc/generators/templates/app/config/application.js +1 -0
  34. data/lib/extjs-mvc/generators/templates/app/config/boot.js +67 -0
  35. data/lib/extjs-mvc/generators/templates/app/config/build.xml +77 -0
  36. data/lib/extjs-mvc/generators/templates/app/config/database.js +4 -0
  37. data/lib/extjs-mvc/generators/templates/app/config/environment.json +58 -0
  38. data/lib/extjs-mvc/generators/templates/app/config/environments/development.json +1 -0
  39. data/lib/extjs-mvc/generators/templates/app/config/environments/production.json +4 -0
  40. data/lib/extjs-mvc/generators/templates/app/config/routes.js +27 -0
  41. data/lib/extjs-mvc/generators/templates/app/config/settings.yml +3 -0
  42. data/lib/extjs-mvc/generators/templates/app/public/index.html +19 -0
  43. data/lib/extjs-mvc/generators/templates/app/public/stylesheets/ext-mvc-all.css +49 -0
  44. data/{test/active_record_test.rb → lib/extjs-mvc/generators/templates/app/spec/SpecHelper.js} +0 -0
  45. data/lib/extjs-mvc/generators/templates/app/spec/index.html +66 -0
  46. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/EXAMPLE.html +68 -0
  47. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/LICENSE +22 -0
  48. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/README.markdown +307 -0
  49. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  50. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.fn.js +29 -0
  51. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.print.js +108 -0
  52. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.assets.js +36 -0
  53. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  54. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.builder.js +80 -0
  55. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.css +90 -0
  56. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.events.js +42 -0
  57. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.matchers.js +145 -0
  58. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.server.js +21 -0
  59. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  60. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/matchers_spec.js +237 -0
  61. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/print_spec.js +119 -0
  62. data/{test/controller_test.rb → lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/spec_helper.js} +0 -0
  63. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/suite.html +18 -0
  64. data/lib/extjs-mvc/generators/templates/scaffold/ScaffoldController.js +18 -0
  65. data/lib/extjs-mvc/generators/view.rb +29 -0
  66. data/lib/extjs-mvc/plugin.rb +105 -0
  67. data/lib/extjs-mvc/scripts.rb +15 -0
  68. data/lib/extjs-mvc/settings.rb +75 -0
  69. data/lib/extjs-mvc/setup.rb +5 -0
  70. data/lib/extjs-mvc/stats.rb +241 -0
  71. data/lib/extjs-mvc/test.rb +11 -0
  72. data/lib/extjs-mvc/testserver.ru +95 -0
  73. data/lib/extjs-mvc/ui.rb +58 -0
  74. data/lib/extjs-mvc/update.rb +73 -0
  75. data/lib/extjs-mvc.rb +70 -32
  76. data/lib/js/App.js +219 -0
  77. data/lib/js/MVC.js +260 -0
  78. data/lib/js/Presenter.js +52 -0
  79. data/lib/js/README.rdoc +69 -0
  80. data/lib/js/build +21 -0
  81. data/lib/js/controller/Controller.js +278 -0
  82. data/lib/js/controller/CrudController.js +460 -0
  83. data/lib/js/lib/Array.js +26 -0
  84. data/lib/js/lib/Booter.js +415 -0
  85. data/lib/js/lib/ClassManager.js +191 -0
  86. data/lib/js/lib/ControllerClassManager.js +95 -0
  87. data/lib/js/lib/Dependencies.js +44 -0
  88. data/lib/js/lib/DispatchMatcher.js +98 -0
  89. data/lib/js/lib/Dispatcher.js +129 -0
  90. data/lib/js/lib/Environment.js +43 -0
  91. data/lib/js/lib/Inflector.js +138 -0
  92. data/lib/js/lib/ModelClassManager.js +19 -0
  93. data/lib/js/lib/Route.js +139 -0
  94. data/lib/js/lib/Router.js +282 -0
  95. data/lib/js/lib/String.js +94 -0
  96. data/lib/js/lib/ViewClassManager.js +229 -0
  97. data/lib/js/lib/notes.txt +32 -0
  98. data/lib/js/model/AdapterManager.js +30 -0
  99. data/lib/js/model/Association.js +26 -0
  100. data/lib/js/model/Base.js +63 -0
  101. data/lib/js/model/BelongsToAssociation.js +116 -0
  102. data/lib/js/model/Cache.js +131 -0
  103. data/lib/js/model/HasManyAssociation.js +160 -0
  104. data/lib/js/model/Model.js +331 -0
  105. data/lib/js/model/UrlBuilder.js +106 -0
  106. data/lib/js/model/adapters/AbstractAdapter.js +296 -0
  107. data/lib/js/model/adapters/MemoryAdapter.js +103 -0
  108. data/lib/js/model/adapters/RESTAdapter.js +345 -0
  109. data/lib/js/model/adapters/RESTJSONAdapter.js +68 -0
  110. data/lib/js/model/adapters/notes.txt +42 -0
  111. data/lib/js/model/associations/Association.js +192 -0
  112. data/lib/js/model/associations/notes.txt +87 -0
  113. data/lib/js/model/validations/Errors.js +136 -0
  114. data/lib/js/model/validations/Plugin.js +139 -0
  115. data/lib/js/model/validations/Validations.js +276 -0
  116. data/lib/js/notes/Charts.graffle +0 -0
  117. data/lib/js/overrides/Ext.Component.js +21 -0
  118. data/lib/js/overrides/Ext.extend.js +142 -0
  119. data/lib/js/spec/Array.spec.js +15 -0
  120. data/lib/js/spec/ExtMVC.spec.js +65 -0
  121. data/lib/js/spec/Model.spec.js +370 -0
  122. data/lib/js/spec/OS.spec.js +83 -0
  123. data/lib/js/spec/Router.spec.js +99 -0
  124. data/lib/js/spec/SpecHelper.js +106 -0
  125. data/lib/js/spec/String.spec.js +83 -0
  126. data/lib/js/spec/model/AbstractAdapter.spec.js +49 -0
  127. data/lib/js/spec/model/Associations.spec.js +99 -0
  128. data/lib/js/spec/model/Cache.spec.js +5 -0
  129. data/lib/js/spec/model/RESTAdapter.spec.js +19 -0
  130. data/lib/js/spec/model/ValidationErrors.spec.js +64 -0
  131. data/lib/js/spec/model/Validations.spec.js +166 -0
  132. data/lib/js/spec/model/ValidationsPlugin.spec.js +108 -0
  133. data/lib/js/spec/suite.html +60 -0
  134. data/lib/js/specs-old/JSSpec.css +216 -0
  135. data/lib/js/specs-old/JSSpec.js +1512 -0
  136. data/lib/js/specs-old/all.html +66 -0
  137. data/lib/js/specs-old/base.js +14 -0
  138. data/lib/js/specs-old/controller.js +17 -0
  139. data/lib/js/specs-old/diff_match_patch.js +1 -0
  140. data/lib/js/specs-old/model.js +70 -0
  141. data/lib/js/specs-old/route.js +38 -0
  142. data/lib/js/specs-old/router.js +59 -0
  143. data/lib/js/specs-old/string.js +22 -0
  144. data/lib/js/testrunner/JSpecFormatter.js +111 -0
  145. data/lib/js/testrunner/TestClient.js +181 -0
  146. data/lib/js/testrunner/TestGrid.js +351 -0
  147. data/lib/js/testrunner/TestRunner.js +110 -0
  148. data/lib/js/testrunner/TestViewport.js +94 -0
  149. data/lib/js/vendor/screw-unit/EXAMPLE.html +68 -0
  150. data/lib/js/vendor/screw-unit/LICENSE +22 -0
  151. data/lib/js/vendor/screw-unit/README.markdown +307 -0
  152. data/lib/js/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  153. data/lib/js/vendor/screw-unit/lib/jquery.fn.js +29 -0
  154. data/lib/js/vendor/screw-unit/lib/jquery.print.js +108 -0
  155. data/lib/js/vendor/screw-unit/lib/screw.assets.js +36 -0
  156. data/lib/js/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  157. data/lib/js/vendor/screw-unit/lib/screw.builder.js +80 -0
  158. data/lib/js/vendor/screw-unit/lib/screw.css +91 -0
  159. data/lib/js/vendor/screw-unit/lib/screw.events.js +42 -0
  160. data/lib/js/vendor/screw-unit/lib/screw.matchers.js +145 -0
  161. data/lib/js/vendor/screw-unit/lib/screw.server.js +21 -0
  162. data/lib/js/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  163. data/lib/js/vendor/screw-unit/spec/matchers_spec.js +237 -0
  164. data/lib/js/vendor/screw-unit/spec/print_spec.js +119 -0
  165. data/{test/data_mapper_test.rb → lib/js/vendor/screw-unit/spec/spec_helper.js} +0 -0
  166. data/lib/js/vendor/screw-unit/spec/suite.html +18 -0
  167. data/lib/js/view/FormWindow.js +184 -0
  168. data/lib/js/view/HasManyEditorGridPanel.js +211 -0
  169. data/lib/js/view/scaffold/Edit.js +46 -0
  170. data/lib/js/view/scaffold/Index.js +561 -0
  171. data/lib/js/view/scaffold/New.js +20 -0
  172. data/lib/js/view/scaffold/ScaffoldFormPanel.js +255 -0
  173. data/test/helper.rb +10 -0
  174. data/test/test_extjs-mvc-gem.rb +7 -0
  175. metadata +232 -56
  176. data/README +0 -12
  177. data/lib/controller/controller.rb +0 -28
  178. data/lib/core_ext/array/extract_options.rb +0 -15
  179. data/lib/extjs/component.rb +0 -71
  180. data/lib/extjs/data/store.rb +0 -131
  181. data/lib/helpers/component.rb +0 -37
  182. data/lib/helpers/store.rb +0 -7
  183. data/lib/model/active_record.rb +0 -89
  184. data/lib/model/base.rb +0 -370
  185. data/lib/model/data_mapper.rb +0 -66
  186. data/lib/model/mongo_mapper.rb +0 -64
  187. data/lib/test/macros.rb +0 -20
  188. data/test/app/config/application.rb +0 -70
  189. data/test/app/config/database.yml +0 -3
  190. data/test/app/db/schema.rb +0 -75
  191. data/test/app/models/active_record/address.rb +0 -4
  192. data/test/app/models/active_record/data_type.rb +0 -3
  193. data/test/app/models/active_record/group.rb +0 -4
  194. data/test/app/models/active_record/house.rb +0 -4
  195. data/test/app/models/active_record/location.rb +0 -5
  196. data/test/app/models/active_record/person.rb +0 -4
  197. data/test/app/models/active_record/user.rb +0 -6
  198. data/test/app/models/active_record/user_group.rb +0 -4
  199. data/test/component_test.rb +0 -15
  200. data/test/debug.log +0 -2969
  201. data/test/model_test.rb +0 -526
  202. data/test/mongo_mapper_test.rb +0 -0
  203. data/test/store_test.rb +0 -0
  204. data/test/test_helper.rb +0 -32
data/test/model_test.rb DELETED
@@ -1,526 +0,0 @@
1
- require 'test_helper'
2
-
3
- ##
4
- # create a couple of related instances.
5
- #
6
- p = Person.create(:first => "Chris", :last => "Scott", :email => "chris@scott.com")
7
- u = User.create(:password => "1234", :person => p)
8
-
9
- class BogusModel
10
- include ExtJS::Model
11
- def additional_attribute
12
- 'computed value'
13
- end
14
- class << self
15
- def extjs_allow_blank(col)
16
- true
17
- end
18
-
19
- def extjs_default(col)
20
- nil
21
- end
22
-
23
- def extjs_type(col)
24
- nil
25
- end
26
-
27
- def extjs_column_names
28
- [:one, :two, :three_id]
29
- end
30
-
31
- def extjs_columns_hash
32
- {
33
- :one => {},
34
- :two => {},
35
- :three_id => {}
36
- }
37
- end
38
-
39
- def extjs_polymorphic_type(id_column_name)
40
- id_column_name.to_s.gsub(/_id\Z/, '_type').to_sym
41
- end
42
-
43
- def extjs_primary_key
44
- :id
45
- end
46
-
47
- def extjs_associations
48
- {
49
- :three => {
50
- :name => :tree,
51
- :type => :belongs_to,
52
- :class => nil,
53
- :foreign_key => :three_id,
54
- :is_polymorphic => false
55
- }
56
- }
57
- end
58
- end
59
- end
60
-
61
-
62
- class BogusModelChild < BogusModel
63
- end
64
-
65
- class ModelTest < Test::Unit::TestCase
66
- context "Rendering DataReader configuration for Person and User" do
67
-
68
- setup do
69
- App.clean_all
70
- end
71
-
72
- should "Person and User should render a valid Reader config" do
73
- reader = Person.extjs_record
74
- assert reader.kind_of?(Hash) && reader.has_key?(:fields) && reader.has_key?(:idProperty)
75
- end
76
- should "Person instance should render with to_record, a Hash containing at least a primary_key" do
77
- rec = Person.first.to_record
78
- assert_kind_of(Hash, rec)
79
- assert_array_has_item(rec.keys, 'has primary key') { |i| i.to_s == Person.extjs_primary_key.to_s }
80
- end
81
- should "User should render a Reader config" do
82
- reader = User.extjs_record
83
- assert reader.kind_of?(Hash) && reader.has_key?(:fields) && reader.has_key?(:idProperty)
84
- end
85
- should "User instance should render with to_record, a Hash containing at least a primary_key" do
86
- rec = User.first.to_record
87
- assert rec.kind_of?(Hash) && rec.keys.include?(User.extjs_primary_key)
88
- end
89
- should "User instance should render to_record containing foreign_key of Person" do
90
- rec = User.first.to_record
91
- assn = User.extjs_associations[:person]
92
- assert rec.keys.include?(assn[:foreign_key])
93
- end
94
-
95
- end
96
-
97
- context "A User with HABTM relationship with Group" do
98
- setup do
99
- App.clean_all
100
- UserGroup.destroy_all
101
-
102
- @user = User.first
103
- UserGroup.create(:user => @user, :group => Group.create(:title => "Merb"))
104
- UserGroup.create(:user => @user, :group => Group.create(:title => "Rails"))
105
- end
106
-
107
- should "Render to_record should return 2 groups" do
108
- User.extjs_fields(:groups)
109
- assert @user.to_record[:groups].length == 2
110
- end
111
- end
112
-
113
- context "A User with Person relationship: User.extjs_fields(:password, :person => [:first, {:last => {'sortDir' => 'ASC'}}])" do
114
- setup do
115
- App.clean_all
116
- User.extjs_fields(:password, {:person => [:first, {:last => {:sortDir => "ASC"}}]})
117
- @fields = User.extjs_record[:fields]
118
- end
119
-
120
- should "User should render a Reader with 4 total fields" do
121
- assert @fields.count === 4
122
- end
123
- should "Reader fields should contain 'password' field" do
124
- assert_array_has_item(@fields, 'has password field') {|f| f[:name] === "password"}
125
- end
126
- should "Reader fields should contain person_id" do
127
- assns = User.extjs_associations
128
- assn = assns[:person]
129
- assert_array_has_item(@fields, 'has foreign key person_id') {|f| f[:name] === assns[:person][:foreign_key].to_s }
130
- end
131
- should "Reader fields should contain mapped field 'person.first'" do
132
- assert_array_has_item(@fields, 'has person_first') {|f| f[:name] === "person_first" and f[:mapping] === "person.first"}
133
- end
134
- should "Reader fields should contain mapped field 'person.last'" do
135
- assert_array_has_item(@fields, 'has person_last') {|f| f[:name] === "person_last" and f[:mapping] === "person.last"}
136
- end
137
- should "person.last should have additional configuration 'sortDir' => 'ASC'" do
138
- assert_array_has_item(@fields, 'has person.last with sortDir') {|f| f[:name] === "person_last" and f[:sortDir] === 'ASC' }
139
- end
140
-
141
- should "produce a valid to_record record" do
142
- person = Person.create!(:first => 'first', :last => 'last', :email => 'email')
143
- user = User.create!(:person_id => person.id, :password => 'password')
144
- record = user.to_record
145
- assert_equal(user.id, record[:id])
146
- assert_equal(person.id, record[:person_id])
147
- assert_equal('password', record[:password])
148
- assert_equal('last', record[:person][:last])
149
- assert_equal('first', record[:person][:first])
150
- end
151
- end
152
-
153
- context "User with standard Person association" do
154
- setup do
155
- App.clean_all
156
- User.extjs_fields(:id, :password, :person)
157
- end
158
- should "produce a valid store config" do
159
- fields = User.extjs_record[:fields]
160
- assert_array_has_item(fields, 'has id') {|f| f[:name] === "id" }
161
- assert_array_has_item(fields, 'has person_id') {|f| f[:name] === "person_id" }
162
- assert_array_has_item(fields, 'has password') {|f| f[:name] === "password" }
163
- assert_array_has_item(fields, 'has person_last') {|f| f[:name] === "person_last" and f[:mapping] == "person.last" }
164
- assert_array_has_item(fields, 'has person_first') {|f| f[:name] === "person_first" and f[:mapping] == "person.first" }
165
- end
166
- should "produce a valid to_record record" do
167
- person = Person.create!(:first => 'first', :last => 'last', :email => 'email')
168
- user = User.create!(:person_id => person.id, :password => 'password')
169
- record = user.to_record
170
- assert_equal(user.id, record[:id])
171
- assert_equal(person.id, record[:person_id])
172
- assert_equal('password', record[:password])
173
- assert_equal('last', record[:person][:last])
174
- assert_equal('first', record[:person][:first])
175
- end
176
- end
177
-
178
- context "Person with User association (has_one relationship)" do
179
- setup do
180
- App.clean_all
181
- User.extjs_fields(:id, :password)
182
- Person.extjs_fields(:id, :user)
183
- end
184
- should "produce a valid store config" do
185
- fields = Person.extjs_record[:fields]
186
- assert_array_has_item(fields, 'has id') {|f| f[:name] === "id" }
187
- assert_array_has_item(fields, 'has user_id') {|f| f[:name] === "user_id" and f[:mapping] == 'user.id' }
188
- assert_array_has_item(fields, 'has user_password') {|f| f[:name] === "user_password"and f[:mapping] == 'user.password' }
189
- end
190
- should "produce a valid to_record record" do
191
- person = Person.create!(:first => 'first', :last => 'last', :email => 'email')
192
- user = User.create!(:person_id => person.id, :password => 'password')
193
- record = person.reload.to_record
194
- assert_equal(person.id, record[:id])
195
- assert_equal(user.id, record[:user][:id])
196
- assert_equal('password', record[:user][:password])
197
- end
198
- end
199
-
200
- context "Person with User association (has_one/belongs_to relationship) cyclic reference" do
201
- setup do
202
- App.clean_all
203
- User.extjs_fields(:id, :person)
204
- Person.extjs_fields(:id, :user)
205
- end
206
- should "produce a valid store config for Person" do
207
- fields = Person.extjs_record[:fields]
208
- assert_array_has_item(fields, 'has id') {|f| f[:name] === "id" }
209
- assert_array_has_item(fields, 'has user_id') {|f| f[:name] === "user_id" and f[:mapping] == 'user.id' }
210
- end
211
- should "produce a valid to_record record for Person" do
212
- person = Person.create!(:first => 'first', :last => 'last', :email => 'email')
213
- user = User.create!(:person_id => person.id, :password => 'password')
214
- record = person.reload.to_record
215
- assert_equal(person.id, record[:id])
216
- assert_equal(user.id, record[:user][:id])
217
- end
218
- end
219
-
220
- context "Fields should render with correct, ExtJS-compatible data-types" do
221
- setup do
222
- App.clean_all
223
- @fields = DataType.extjs_record[:fields]
224
- end
225
-
226
- should "Understand 'string'" do
227
- assert_array_has_item(@fields, 'has string_column with string') {|f| f[:name] == 'string_column' and f[:type] == 'string'}
228
- end
229
- should "Understand 'integer' as 'int'" do
230
- assert_array_has_item(@fields, 'has integer_column with int') {|f| f[:name] == 'integer_column' and f[:type] == 'int'}
231
- end
232
- should "Understand 'float'" do
233
- assert_array_has_item(@fields, 'has float_column with float') {|f| f[:name] == 'float_column' and f[:type] == 'float'}
234
- end
235
- should "Understand 'decimal' as 'float'" do # Is this correct??
236
- assert_array_has_item(@fields, 'has decimal_column with float') {|f| f[:name] == 'decimal_column' and f[:type] == 'float'}
237
- end
238
- should "Understand 'date'" do
239
- assert_array_has_item(@fields, 'has date_column with date') {|f| f[:name] == 'date_column' and f[:type] == 'date'}
240
- end
241
- should "Understand 'datetime' as 'date'" do
242
- assert_array_has_item(@fields, 'has datetime_column with date') {|f| f[:name] == 'datetime_column' and f[:type] == 'date'}
243
- end
244
- should "Understand 'time' as 'date'" do
245
- assert_array_has_item(@fields, 'has time_column with date') {|f| f[:name] == 'time_column' and f[:type] == 'date'}
246
- end
247
- should "Understand 'boolean'" do
248
- assert_array_has_item(@fields, 'has boolean_column with boolean') {|f| f[:name] == 'boolean_column' and f[:type] == 'boolean'}
249
- end
250
- should "Understand NOT NULL" do
251
- assert_array_has_item(@fields, 'has notnull_column with allowBlank == false') {|f| f[:name] == 'notnull_column' and f[:allowBlank] === false}
252
- end
253
- should "Understand DEFAULT" do
254
- assert_array_has_item(@fields, 'has default_column with defaultValue == true') {|f| f[:name] == 'default_column' and f[:defaultValue] === true}
255
- end
256
- end
257
-
258
- context "polymorphic associations" do
259
- setup do
260
- App.clean_all
261
- end
262
-
263
- should "return nil as class for a polymorphic relation" do
264
- assert_equal(nil, Address.extjs_associations[:addressable][:class])
265
- end
266
-
267
- should "create a proper default store config" do
268
- Address.extjs_fields
269
- fields = Address.extjs_record[:fields]
270
- assert_array_has_item(fields, 'has addressable_id') {|f| f[:name] === 'addressable_id' && !f[:mapping] }
271
- assert_array_has_item(fields, 'addressable_type') {|f| f[:name] === 'addressable_type' && !f[:mapping] }
272
- end
273
-
274
- should "create the right store config when including members of the polymorphic association" do
275
- Address.extjs_fields :street, :addressable => [:name]
276
- fields = Address.extjs_record[:fields]
277
- assert_array_has_item(fields, "has addressable_name") {|f| f[:name] === 'addressable_name' && f[:mapping] === 'addressable.name'}
278
- assert_array_has_item(fields, "has addressable_id") {|f| f[:name] === 'addressable_id' && !f[:mapping] }
279
- assert_array_has_item(fields, "has addressable_type") {|f| f[:name] === 'addressable_type' && !f[:mapping] }
280
- end
281
-
282
- should "fill in the right values for to_record" do
283
- Address.extjs_fields :street, :addressable => [:name]
284
- location = Location.create!(:name => 'Home')
285
- address = location.create_address(:street => 'Main Street 1')
286
- record = address.to_record
287
- assert_equal({:name => "Home", :id => location.id}, record[:addressable])
288
- assert_equal("Location", record[:addressable_type])
289
- assert_equal(location.id, record[:addressable_id])
290
- assert_equal(address.id, record[:id])
291
- assert_equal("Main Street 1", record[:street])
292
- end
293
- end
294
-
295
- context "single table inheritance" do
296
- setup do
297
- App.clean_all
298
- end
299
-
300
- should "fieldsets should be accessible from descendants" do
301
- Location.extjs_fieldset :on_location, [:street]
302
- fields = House.extjs_record(:on_location)[:fields]
303
- assert_array_has_item(fields, 'has street') {|f| f[:name] === 'street' }
304
- assert_array_has_not_item(fields, 'has name') {|f| f[:name] === 'name' }
305
- end
306
- should "fieldsets should be overrideable from descendants" do
307
- Location.extjs_fieldset :override, [:street]
308
- House.extjs_fieldset :override, [:name]
309
- fields = House.extjs_record(:override)[:fields]
310
- assert_array_has_not_item(fields, 'has street') {|f| f[:name] === 'street' }
311
- assert_array_has_item(fields, 'has name') {|f| f[:name] === 'name' }
312
- end
313
- end
314
-
315
- context "ExtJS::Model::Util" do
316
- context "#extract_fieldset_and_options default" do
317
- setup do
318
- @fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options [:fields => [:one, :two, :three]]
319
- @fields = @options[:fields]
320
- end
321
- should "return :default when no fieldset provided" do
322
- assert_equal(:'default', @fieldset)
323
- end
324
- should "not alter the fields array" do
325
- assert_equal([:one, :two, :three], @fields)
326
- end
327
- end
328
-
329
- context "#extract_fieldset_and_options with explicit fieldset definition and array with fields" do
330
- setup do
331
- @fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options [:explicit, [:one, :two, :three]]
332
- @fields = @options[:fields]
333
- end
334
- should "return :default when no fieldset provided" do
335
- assert_equal(:'explicit', @fieldset)
336
- end
337
- should "not alter the fields array" do
338
- assert_equal([:one, :two, :three], @fields)
339
- end
340
- end
341
-
342
- context "#extract_fieldset_and_options with explicit fieldset definition and hash with fields" do
343
- setup do
344
- @fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options [:explicit, {:fields => [:one, :two, :three]}]
345
- @fields = @options[:fields]
346
- end
347
- should "return :default when no fieldset provided" do
348
- assert_equal(:'explicit', @fieldset)
349
- end
350
- should "not alter the fields array" do
351
- assert_equal([:one, :two, :three], @fields)
352
- end
353
- end
354
-
355
- context "#extract_fieldset_and_options with only a hash" do
356
- setup do
357
- @fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options [{:fieldset => :explicit, :fields => [:one, :two, :three]}]
358
- @fields = @options[:fields]
359
- end
360
- should "return :default when no fieldset provided" do
361
- assert_equal(:'explicit', @fieldset)
362
- end
363
- should "not alter the fields array" do
364
- assert_equal([:one, :two, :three], @fields)
365
- end
366
- end
367
-
368
- context "#extract_fieldset_and_options edge cases" do
369
- should "called without arguments" do
370
- @fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options []
371
- @fields = @options[:fields]
372
- assert_equal(:'default', @fieldset)
373
- assert_equal([], @fields)
374
- end
375
- should "called with only the fieldset and no field arguments" do
376
- @fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options [:explicit]
377
- @fields = @options[:fields]
378
- assert_equal(:'explicit', @fieldset)
379
- assert_equal([], @fields)
380
- end
381
- should "raise error when called with more than 2 arguments" do
382
- assert_raise(ArgumentError) { ExtJS::Model::Util.extract_fieldset_and_options [:explicit, :some, {}] }
383
- end
384
- should "raise error when called with 2 arguments and the first one is no symbol" do
385
- assert_raise(ArgumentError) { ExtJS::Model::Util.extract_fieldset_and_options [{ :fields => [] }, :explicit] }
386
- end
387
- end
388
- end
389
-
390
- context "ExtJS::Model::ClassMethods" do
391
-
392
- context "#process_fields" do
393
- should "handle a simple Array of Symbols" do
394
- @fields = BogusModel.process_fields :one, :two, :three
395
- assert_equal([{:name => :one}, {:name => :two}, {:name => :three}], @fields)
396
- end
397
- should "handle a mixed Array where the last item is a Hash" do
398
- @fields = BogusModel.process_fields :one, :two, :three => [:three_one, :three_two]
399
- assert_equal([{:name => :one}, {:name => :two}, {:name => :three, :fields => [{:name => :three_one}, {:name => :three_two}]}], @fields)
400
- end
401
- should "handle a mixed Array where a middle item is a Hash" do
402
- @fields = BogusModel.process_fields :one, {:two => [:two_one, :two_two]}, :three
403
- assert_equal([
404
- {:name => :one},
405
- {:name => :two, :fields => [{:name => :two_one}, {:name => :two_two}]},
406
- {:name => :three}], @fields)
407
- end
408
- should "handle option :only" do
409
- @fields = BogusModel.process_fields :only => [:one, :two, :three]
410
- assert_equal([{:name => :one}, {:name => :two}, {:name => :three}], @fields)
411
- end
412
- should "handle option :exclude" do
413
- @fields = BogusModel.process_fields :exclude => [:two]
414
- assert_equal([{:name => :one}, {:name => :three_id}], @fields)
415
- end
416
- should "handle option :additional" do
417
- @fields = BogusModel.process_fields :additional => [:additional_attribute]
418
- assert_equal([{:name => :one}, {:name => :two}, {:name => :three_id}, {:name => :additional_attribute}], @fields)
419
-
420
- end
421
- should "handle {:field => {:sortDir => 'ASC'}}" do
422
- @fields = BogusModel.process_fields({:field => {:sortDir => 'ASC'}})
423
- assert_equal([{:name => :field, :sortDir => 'ASC'}], @fields)
424
- end
425
- should "handle recursive definition" do
426
- @fields = BogusModel.process_fields(:one, {:three => [{:one => [:one, :two]}, {:two => {:sortDir => "ASC"}}]})
427
- assert_equal([{:name => :one}, {:name => :three, :fields => [{:name => :one, :fields => [{:name => :one}, {:name => :two}]}, {:name => :two, :sortDir => 'ASC'}]}], @fields)
428
- end
429
- should "not touch already correct fields" do
430
- @fields = BogusModel.process_fields(:one, {:name => :field,:sortDir => 'ASC'})
431
- assert_equal([{:name => :one},{:name => :field, :sortDir => 'ASC'}], @fields)
432
- end
433
- should "raise ArgumentError when pass in bogus hash" do
434
- assert_raise(ArgumentError) { @fields = BogusModel.process_fields(:one, {:nme => :field,:sortDir => 'ASC'}) }
435
- end
436
- end
437
-
438
- context "#extjs_field" do
439
- should "type gets set to 'auto' when not present" do
440
- @field = BogusModel.extjs_field({:name => :test})
441
- assert_equal('auto', @field[:type])
442
- end
443
- should "not touch type when alredy present" do
444
- @field = BogusModel.extjs_field({:name => :test, :type => 'untouched'})
445
- assert_equal('untouched', @field[:type])
446
- end
447
- should "raise exception when bogus field config passed" do
448
- assert_raise(ArgumentError) { BogusModel.extjs_field({:name => :test, "type" => 'untouched'}) }
449
- end
450
-
451
- end
452
-
453
- context "#extjs_field with ORM config" do
454
- should "set allowBlank" do
455
- BogusModel.expects(:extjs_allow_blank).returns(false)
456
- @field = BogusModel.extjs_field({:name => :test}, stub())
457
- assert_equal(false, @field[:allowBlank])
458
- end
459
- should "set type" do
460
- BogusModel.expects(:extjs_type).returns('int')
461
- @field = BogusModel.extjs_field({:name => :test}, stub())
462
- assert_equal('int', @field[:type])
463
- end
464
- should "set defaultValue" do
465
- BogusModel.expects(:extjs_default).returns(true)
466
- @field = BogusModel.extjs_field({:name => :test}, stub())
467
- assert_equal(true, @field[:defaultValue])
468
- end
469
- should "set dateFormat to c it's a date" do
470
- BogusModel.expects(:extjs_type).returns('date')
471
- @field = BogusModel.extjs_field({:name => :test}, stub())
472
- assert_equal('c', @field[:dateFormat])
473
- end
474
- should "not touch dateFormat if it's already set" do
475
- BogusModel.expects(:extjs_type).returns('date')
476
- @field = BogusModel.extjs_field({:name => :test, :dateFormat => 'not-c'}, stub())
477
- assert_equal('not-c', @field[:dateFormat])
478
- end
479
- end
480
-
481
- context "#extjs_field with Hash config" do
482
- should "set correct name and mapping" do
483
- @field = BogusModel.extjs_field({:name => :son}, {:mapping => 'grandfather.father', :parent_trail => 'grandfather_father'})
484
- assert_equal('grandfather_father_son', @field[:name])
485
- assert_equal('grandfather.father.son', @field[:mapping])
486
- end
487
- should "apply config to field" do
488
- @field = BogusModel.extjs_field({:name => :son}, {:sortDir => 'ASC'})
489
- assert_equal('ASC', @field[:sortDir])
490
- end
491
- end
492
-
493
- context "#extjs_get_fields_for_fieldset" do
494
- should "return full list of columns for fieldset that was not defined, yet" do
495
- @fields = BogusModel.extjs_get_fields_for_fieldset :not_there
496
- assert_equal(BogusModel.process_fields(*BogusModel.extjs_column_names), @fields)
497
- end
498
- should "return the right fields for a fieldset that was defined before in the same class" do
499
- BogusModel.extjs_fieldset :fieldset_was_defined, [:one]
500
- @fields = BogusModel.extjs_get_fields_for_fieldset :fieldset_was_defined
501
- assert_equal(BogusModel.process_fields(:one), @fields)
502
- end
503
- should "return the fieldset of the ancestor when it was only defined in the ancestor" do
504
- BogusModel.extjs_fieldset :fieldset_was_defined_in_ancestor, [:one]
505
- @fields = BogusModelChild.extjs_get_fields_for_fieldset :fieldset_was_defined_in_ancestor
506
- assert_equal(BogusModel.process_fields(:one), @fields)
507
- end
508
- should "return the fieldset of the child when it was defined in the child and the ancestor" do
509
- BogusModel.extjs_fieldset :fieldset_was_defined_in_both, [:one]
510
- BogusModelChild.extjs_fieldset :fieldset_was_defined_in_both, [:two]
511
- @fields = BogusModelChild.extjs_get_fields_for_fieldset :fieldset_was_defined_in_both
512
- assert_equal(BogusModel.process_fields(:two), @fields)
513
- end
514
- end
515
- end
516
-
517
- protected
518
- def assert_array_has_item array, item_description, &blk
519
- assert array.find {|i| blk.call(i) }, "The array #{array.inspect} should #{item_description} but it does not"
520
- end
521
- def assert_array_has_not_item array, item_description, &blk
522
- assert !array.find {|i| blk.call(i) }, "The array #{array.inspect} should not #{item_description} but it does"
523
- end
524
-
525
- end
526
-
File without changes
data/test/store_test.rb DELETED
File without changes
data/test/test_helper.rb DELETED
@@ -1,32 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mocha'
5
-
6
- begin
7
- require 'ruby-debug'
8
- rescue LoadError
9
- puts "ruby-debug not loaded"
10
- end
11
-
12
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'app'))
15
-
16
- ROOT = File.join(File.dirname(__FILE__), 'app')
17
- require "config/application"
18
-
19
- ##
20
- # Boot test app.
21
- # TODO, send orm as param from console
22
- # eg: >rake test data_mapper
23
- # >rake test mongo_mapper
24
- #
25
- App = Test::App.new(:active_record)
26
-
27
- #FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
28
-
29
-
30
- class Test::Unit::TestCase
31
- end
32
-