extjs-mvc 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -35,12 +35,21 @@ fields with will be used to render the <tt>Ext.data.Record.create</tt> field-def
35
35
  # OR
36
36
  extjs_fields :name, :description
37
37
 
38
+ # OR
39
+ extjs_fields :only => [:name, :description] # actually the same as above
40
+
41
+ # OR
42
+ extjs_fields :additional => [:computed] # includes all database columns and an additional computed field
43
+
38
44
  # OR define a column as a Hash
39
45
  extjs_fields :description, :name => {"sortDir" => "ASC"}, :created_at => {"dateFormat" => "c"}
40
46
 
41
47
  # OR render associations, association-fields will have their "mapping" property set automatically
42
48
  extjs_fields :name, :description, :company => [:name, :description]
43
49
 
50
+ def computed
51
+ name.blank? ? login : name
52
+ end
44
53
  end
45
54
 
46
55
  After including the model mixin <tt>ExtJS::Model</tt>, try typing the following in <tt>irb</tt> console:
@@ -55,7 +64,7 @@ After including the model mixin <tt>ExtJS::Model</tt>, try typing the following
55
64
  An auto-generated <tt>Ext.data.JsonReader</tt> configuration!
56
65
 
57
66
 
58
- You can also define different sets of fields for different representation of your model.
67
+ You can also define different sets of fields for different representations of your model.
59
68
 
60
69
  E.g. with the following definition:
61
70
 
@@ -168,7 +177,7 @@ In individual model unit tests:
168
177
  future version unintentionally.
169
178
  * Commit, do not mess with rakefile, version, or history.
170
179
  (if you want to have your own version, that is fine but
171
- bump version in a commit by itself I can ignore when I pull)
180
+ bump version in a commit by itself I can ignore when I pull)
172
181
  * Send me a pull request. Bonus points for topic branches.
173
182
 
174
183
  == Copyright
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ begin
12
12
  gem.authors = ["Chris Scott"]
13
13
  gem.add_development_dependency "shoulda"
14
14
  gem.add_development_dependency "mocha"
15
+ gem.add_development_dependency "extlib"
15
16
 
16
17
  gem.test_files = []
17
18
  gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
@@ -23,7 +23,10 @@ module ExtJS
23
23
  # @return {Boolean}
24
24
  #
25
25
  def extjs_allow_blank(col)
26
- col.null
26
+ # if the column is the primary key always allow it to be blank.
27
+ # Otherwise we could not create new records with ExtJS because
28
+ # new records have no id and thus cannot be valid
29
+ col.name == self.primary_key || col.null
27
30
  end
28
31
 
29
32
  ##
data/lib/model/base.rb CHANGED
@@ -247,7 +247,9 @@ module ExtJS
247
247
  fields = []
248
248
  if params.size == 1 && params.last.is_a?(Hash) # peek into argument to see if its an option hash
249
249
  options = params.last
250
- if options.has_key?(:exclude) && options[:exclude].is_a?(Array)
250
+ if options.has_key?(:additional) && options[:additional].is_a?(Array)
251
+ return self.process_fields(*(self.extjs_column_names + options[:additional].map(&:to_sym)))
252
+ elsif options.has_key?(:exclude) && options[:exclude].is_a?(Array)
251
253
  return self.process_fields(*(self.extjs_column_names - options[:exclude].map(&:to_sym)))
252
254
  elsif options.has_key?(:only) && options[:only].is_a?(Array)
253
255
  return self.process_fields(*options[:only])
@@ -0,0 +1,70 @@
1
+ # TODO: Figure out how to iterate each ORM framework AR, DM, MM and test each.
2
+ require 'active_record'
3
+ require 'active_support'
4
+ require 'extjs-mvc'
5
+ require 'extlib/inflection'
6
+
7
+ gem 'sqlite3-ruby'
8
+
9
+ class Test::App
10
+
11
+ attr_reader :models
12
+
13
+ def initialize(orm = :active_record)
14
+ @orm = orm
15
+ @config = YAML::load(IO.read("#{ROOT}/config/database.yml"))
16
+
17
+ # Load ORM
18
+ send("boot_#{orm.to_s}")
19
+
20
+ load_models
21
+
22
+ require 'db/schema'
23
+
24
+ end
25
+
26
+ ##
27
+ # Reset a model's @extjs_fieldsets
28
+ #
29
+ def clean_all
30
+ @models.map { |klass| clean klass }
31
+ end
32
+
33
+
34
+ private
35
+
36
+ def boot_active_record
37
+ ActiveRecord::Base.establish_connection(@config['test'])
38
+ end
39
+
40
+ def boot_mongo_mapper
41
+
42
+ end
43
+
44
+ def boot_data_mapper
45
+
46
+ end
47
+
48
+ ##
49
+ # Do a dir on /models and constantize each filename
50
+ #
51
+ def load_models
52
+ @models = []
53
+ # Load Models and Schema for corresponding orm
54
+ re = /^.*\/(.*).rb$/
55
+ Dir["#{ROOT}/models/#{@orm.to_s}/*"].each { |c|
56
+ require c
57
+ match = c.match(re)
58
+ @models << Extlib::Inflection.constantize(Extlib::Inflection.camelize(match[1])) if match
59
+ }
60
+ end
61
+
62
+ def clean klass
63
+ klass.instance_variables.each do |var_name|
64
+ if /\A@extjs_fieldsets__/ =~ var_name.to_s
65
+ klass.instance_variable_set( var_name.to_sym, nil )
66
+ end
67
+ end
68
+ end
69
+
70
+ end
File without changes
@@ -0,0 +1,75 @@
1
+
2
+ ##
3
+ # build simple database
4
+ #
5
+ # people
6
+ #
7
+ ActiveRecord::Base.connection.create_table :users, :force => true do |table|
8
+ table.column :id, :serial
9
+ table.column :person_id, :integer
10
+ table.column :password, :string
11
+ table.column :created_at, :date
12
+ table.column :disabled, :boolean, :default => true
13
+ end
14
+ ##
15
+ # people
16
+ #
17
+ ActiveRecord::Base.connection.create_table :people, :force => true do |table|
18
+ table.column :id, :serial
19
+ table.column :first, :string, :null => false
20
+ table.column :last, :string, :null => false
21
+ table.column :email, :string, :null => false
22
+ end
23
+ ##
24
+ # user_groups, join table
25
+ #
26
+ ActiveRecord::Base.connection.create_table :user_groups, :force => true do |table|
27
+ table.column :user_id, :integer
28
+ table.column :group_id, :integer
29
+ end
30
+
31
+ ##
32
+ # groups
33
+ #
34
+ ActiveRecord::Base.connection.create_table :groups, :force => true do |table|
35
+ table.column :id, :serial
36
+ table.column :title, :string
37
+ end
38
+
39
+ ##
40
+ # locations
41
+ #
42
+ ActiveRecord::Base.connection.create_table :locations, :force => true do |table|
43
+ table.column :id, :serial
44
+ table.column :name, :string
45
+ table.column :street, :string
46
+ table.column :type, :string
47
+ end
48
+
49
+ ##
50
+ # addresses
51
+ #
52
+ ActiveRecord::Base.connection.create_table :addresses, :force => true do |table|
53
+ table.column :id, :serial
54
+ table.column :addressable_type, :string
55
+ table.column :addressable_id, :integer
56
+ table.column :street, :string
57
+ end
58
+
59
+ ##
60
+ # Mock a Model for testing data-types
61
+ #
62
+ ActiveRecord::Base.connection.create_table :data_types, :force => true do |table|
63
+ table.column :id, :serial
64
+ table.column :string_column, :string
65
+ table.column :decimal_column, :decimal
66
+ table.column :float_column, :float
67
+ table.column :date_column, :date
68
+ table.column :datetime_column, :datetime
69
+ table.column :time_column, :time
70
+ table.column :email, :string
71
+ table.column :integer_column, :integer
72
+ table.column :notnull_column, :string, :null => false
73
+ table.column :default_column, :boolean, :default => true
74
+ table.column :boolean_column, :boolean
75
+ end
@@ -0,0 +1,4 @@
1
+ class Address < ActiveRecord::Base
2
+ belongs_to :addressable, :polymorphic => true
3
+ include ExtJS::Model
4
+ end
@@ -0,0 +1,3 @@
1
+ class DataType < ActiveRecord::Base
2
+ include ExtJS::Model
3
+ end
@@ -0,0 +1,4 @@
1
+ class Group < ActiveRecord::Base
2
+ has_many :users
3
+ include ExtJS::Model
4
+ end
@@ -0,0 +1,4 @@
1
+ require "#{File.dirname(__FILE__)}/location"
2
+
3
+ class House < Location
4
+ end
@@ -0,0 +1,5 @@
1
+ class Location < ActiveRecord::Base
2
+ has_one :address, :as => :addressable
3
+ include ExtJS::Model
4
+ end
5
+
@@ -0,0 +1,4 @@
1
+ class Person < ActiveRecord::Base
2
+ has_one :user
3
+ include ExtJS::Model
4
+ end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+ include ExtJS::Model
3
+ belongs_to :person
4
+
5
+ has_and_belongs_to_many :groups, :join_table => :user_groups
6
+ end
@@ -0,0 +1,4 @@
1
+ class UserGroup < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :group
4
+ end
data/test/model_test.rb CHANGED
@@ -1,7 +1,16 @@
1
1
  require 'test_helper'
2
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
+
3
9
  class BogusModel
4
10
  include ExtJS::Model
11
+ def additional_attribute
12
+ 'computed value'
13
+ end
5
14
  class << self
6
15
  def extjs_allow_blank(col)
7
16
  true
@@ -57,7 +66,7 @@ class ModelTest < Test::Unit::TestCase
57
66
  context "Rendering DataReader configuration for Person and User" do
58
67
 
59
68
  setup do
60
- clean_all
69
+ App.clean_all
61
70
  end
62
71
 
63
72
  should "Person and User should render a valid Reader config" do
@@ -87,7 +96,7 @@ class ModelTest < Test::Unit::TestCase
87
96
 
88
97
  context "A User with HABTM relationship with Group" do
89
98
  setup do
90
- clean_all
99
+ App.clean_all
91
100
  UserGroup.destroy_all
92
101
 
93
102
  @user = User.first
@@ -103,7 +112,7 @@ class ModelTest < Test::Unit::TestCase
103
112
 
104
113
  context "A User with Person relationship: User.extjs_fields(:password, :person => [:first, {:last => {'sortDir' => 'ASC'}}])" do
105
114
  setup do
106
- clean_all
115
+ App.clean_all
107
116
  User.extjs_fields(:password, {:person => [:first, {:last => {:sortDir => "ASC"}}]})
108
117
  @fields = User.extjs_record[:fields]
109
118
  end
@@ -143,7 +152,7 @@ class ModelTest < Test::Unit::TestCase
143
152
 
144
153
  context "User with standard Person association" do
145
154
  setup do
146
- clean_all
155
+ App.clean_all
147
156
  User.extjs_fields(:id, :password, :person)
148
157
  end
149
158
  should "produce a valid store config" do
@@ -168,7 +177,7 @@ class ModelTest < Test::Unit::TestCase
168
177
 
169
178
  context "Person with User association (has_one relationship)" do
170
179
  setup do
171
- clean_all
180
+ App.clean_all
172
181
  User.extjs_fields(:id, :password)
173
182
  Person.extjs_fields(:id, :user)
174
183
  end
@@ -190,7 +199,7 @@ class ModelTest < Test::Unit::TestCase
190
199
 
191
200
  context "Person with User association (has_one/belongs_to relationship) cyclic reference" do
192
201
  setup do
193
- clean_all
202
+ App.clean_all
194
203
  User.extjs_fields(:id, :person)
195
204
  Person.extjs_fields(:id, :user)
196
205
  end
@@ -210,7 +219,7 @@ class ModelTest < Test::Unit::TestCase
210
219
 
211
220
  context "Fields should render with correct, ExtJS-compatible data-types" do
212
221
  setup do
213
- clean_all
222
+ App.clean_all
214
223
  @fields = DataType.extjs_record[:fields]
215
224
  end
216
225
 
@@ -248,7 +257,7 @@ class ModelTest < Test::Unit::TestCase
248
257
 
249
258
  context "polymorphic associations" do
250
259
  setup do
251
- clean_all
260
+ App.clean_all
252
261
  end
253
262
 
254
263
  should "return nil as class for a polymorphic relation" do
@@ -285,7 +294,7 @@ class ModelTest < Test::Unit::TestCase
285
294
 
286
295
  context "single table inheritance" do
287
296
  setup do
288
- clean_all
297
+ App.clean_all
289
298
  end
290
299
 
291
300
  should "fieldsets should be accessible from descendants" do
@@ -404,6 +413,11 @@ class ModelTest < Test::Unit::TestCase
404
413
  @fields = BogusModel.process_fields :exclude => [:two]
405
414
  assert_equal([{:name => :one}, {:name => :three_id}], @fields)
406
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
407
421
  should "handle {:field => {:sortDir => 'ASC'}}" do
408
422
  @fields = BogusModel.process_fields({:field => {:sortDir => 'ASC'}})
409
423
  assert_equal([{:name => :field, :sortDir => 'ASC'}], @fields)
data/test/test_helper.rb CHANGED
@@ -3,166 +3,30 @@ require 'test/unit'
3
3
  require 'shoulda'
4
4
  require 'mocha'
5
5
 
6
- require 'active_record'
7
- require 'active_support'
8
-
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
- $LOAD_PATH.unshift(File.dirname(__FILE__))
11
-
12
- require 'extjs-mvc'
13
-
14
- gem 'sqlite3-ruby'
15
-
16
6
  begin
17
7
  require 'ruby-debug'
18
8
  rescue LoadError
19
9
  puts "ruby-debug not loaded"
20
10
  end
21
11
 
22
- ROOT = File.join(File.dirname(__FILE__), '..')
23
- RAILS_ROOT = ROOT
24
- RAILS_ENV = "test"
25
-
26
- FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
27
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
28
- #ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
29
- ActiveRecord::Base.establish_connection(config['test'])
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'))
30
15
 
16
+ ROOT = File.join(File.dirname(__FILE__), 'app')
17
+ require "config/application"
31
18
 
32
19
  ##
33
- # build User / Person models
34
- # Move AR-specific stuff to AR test adapter
20
+ # Boot test app.
21
+ # TODO, send orm as param from console
22
+ # eg: >rake test data_mapper
23
+ # >rake test mongo_mapper
35
24
  #
36
- class User < ActiveRecord::Base
37
- include ExtJS::Model
38
- belongs_to :person
39
- #has_many :user_groups
40
- #has_many :groups, :through => :user_groups
41
- has_and_belongs_to_many :groups, :join_table => :user_groups
42
-
43
- end
44
-
45
- class Person < ActiveRecord::Base
46
- has_one :user
47
- include ExtJS::Model
48
- end
49
-
50
- class DataType < ActiveRecord::Base
51
- include ExtJS::Model
52
- end
53
-
54
- class UserGroup < ActiveRecord::Base
55
- belongs_to :user
56
- belongs_to :group
57
- end
25
+ App = Test::App.new(:active_record)
58
26
 
59
- class Group < ActiveRecord::Base
60
- has_many :users
61
- include ExtJS::Model
62
- end
27
+ #FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
63
28
 
64
- class Location < ActiveRecord::Base
65
- has_one :address, :as => :addressable
66
- include ExtJS::Model
67
- end
68
- class House < Location
69
- end
70
- class Address < ActiveRecord::Base
71
- belongs_to :addressable, :polymorphic => true
72
- include ExtJS::Model
73
- end
74
29
 
75
30
  class Test::Unit::TestCase
76
31
  end
77
32
 
78
- ##
79
- # build simple database
80
- #
81
- # people
82
- #
83
- ActiveRecord::Base.connection.create_table :users, :force => true do |table|
84
- table.column :id, :serial
85
- table.column :person_id, :integer
86
- table.column :password, :string
87
- table.column :created_at, :date
88
- table.column :disabled, :boolean, :default => true
89
- end
90
- ##
91
- # people
92
- #
93
- ActiveRecord::Base.connection.create_table :people, :force => true do |table|
94
- table.column :id, :serial
95
- table.column :first, :string, :null => false
96
- table.column :last, :string, :null => false
97
- table.column :email, :string, :null => false
98
- end
99
- ##
100
- # user_groups, join table
101
- #
102
- ActiveRecord::Base.connection.create_table :user_groups, :force => true do |table|
103
- table.column :user_id, :integer
104
- table.column :group_id, :integer
105
- end
106
-
107
- ##
108
- # groups
109
- #
110
- ActiveRecord::Base.connection.create_table :groups, :force => true do |table|
111
- table.column :id, :serial
112
- table.column :title, :string
113
- end
114
-
115
- ##
116
- # locations
117
- #
118
- ActiveRecord::Base.connection.create_table :locations, :force => true do |table|
119
- table.column :id, :serial
120
- table.column :name, :string
121
- table.column :street, :string
122
- table.column :type, :string
123
- end
124
-
125
- ##
126
- # addresses
127
- #
128
- ActiveRecord::Base.connection.create_table :addresses, :force => true do |table|
129
- table.column :id, :serial
130
- table.column :addressable_type, :string
131
- table.column :addressable_id, :integer
132
- table.column :street, :string
133
- end
134
-
135
- ##
136
- # Mock a Model for testing data-types
137
- #
138
- ActiveRecord::Base.connection.create_table :data_types, :force => true do |table|
139
- table.column :id, :serial
140
- table.column :string_column, :string
141
- table.column :decimal_column, :decimal
142
- table.column :float_column, :float
143
- table.column :date_column, :date
144
- table.column :datetime_column, :datetime
145
- table.column :time_column, :time
146
- table.column :email, :string
147
- table.column :integer_column, :integer
148
- table.column :notnull_column, :string, :null => false
149
- table.column :default_column, :boolean, :default => true
150
- table.column :boolean_column, :boolean
151
- end
152
-
153
- ##
154
- # create a couple of related instances.
155
- #
156
- p = Person.create(:first => "Chris", :last => "Scott", :email => "chris@scott.com")
157
- u = User.create(:password => "1234", :person => p)
158
-
159
- def clean klass
160
- klass.instance_variables.each do |var_name|
161
- if /\A@extjs_fieldsets__/ =~ var_name.to_s
162
- klass.instance_variable_set( var_name.to_sym, nil )
163
- end
164
- end
165
- end
166
- def clean_all
167
- [User, Person, DataType, UserGroup, Group, Location, House, Address].map { |klass| clean klass }
168
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extjs-mvc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Scott
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-21 00:00:00 -05:00
12
+ date: 2010-02-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: extlib
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
35
45
  description: MVC tools to assist with ExtJS development in Rails and Merb
36
46
  email: christocracy@gmail.com
37
47
  executables: []
@@ -61,10 +71,20 @@ files:
61
71
  - lib/model/mongo_mapper.rb
62
72
  - lib/test/macros.rb
63
73
  - test/active_record_test.rb
74
+ - test/app/config/application.rb
75
+ - test/app/config/database.yml
76
+ - test/app/db/schema.rb
77
+ - test/app/models/active_record/address.rb
78
+ - test/app/models/active_record/data_type.rb
79
+ - test/app/models/active_record/group.rb
80
+ - test/app/models/active_record/house.rb
81
+ - test/app/models/active_record/location.rb
82
+ - test/app/models/active_record/person.rb
83
+ - test/app/models/active_record/user.rb
84
+ - test/app/models/active_record/user_group.rb
64
85
  - test/component_test.rb
65
86
  - test/controller_test.rb
66
87
  - test/data_mapper_test.rb
67
- - test/database.yml
68
88
  - test/debug.log
69
89
  - test/model_test.rb
70
90
  - test/mongo_mapper_test.rb