extjs-mvc 0.2.7 → 0.2.8

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/test/model_test.rb CHANGED
@@ -1,20 +1,116 @@
1
1
  require 'test_helper'
2
2
 
3
- class TestParent < ActiveRecord::Base
4
-
5
- end
3
+ class ModelTest < Test::Unit::TestCase
4
+ context "Rendering DataReader configuration for Person and User" do
6
5
 
7
- class TestModel < ActiveRecord::Base
8
- include ExtJS::Model
9
- belongs_to :test_parent
6
+ setup do
7
+ # common stuff for all tests.
8
+ end
10
9
 
11
- #for the EXT Store configuration
12
- extjs_fields :name, :test_parent => [:name]
13
- end
10
+ should "Person and User should render a valid Reader config" do
11
+ reader = Person.extjs_record
12
+ assert reader.kind_of?(Hash) && reader.has_key?("fields") && reader.has_key?("idProperty")
13
+ end
14
+ should "Person instance should render with to_record, a Hash containing at least a primary_key" do
15
+ rec = Person.first.to_record
16
+ assert rec.kind_of?(Hash) && rec.keys.include?(Person.extjs_primary_key.to_s)
17
+ end
18
+ should "User should render a Reader config" do
19
+ reader = User.extjs_record
20
+ assert reader.kind_of?(Hash) && reader.has_key?("fields") && reader.has_key?("idProperty")
21
+ end
22
+ should "User instance should render with to_record, a Hash containing at least a primary_key" do
23
+ rec = User.first.to_record
24
+ assert rec.kind_of?(Hash) && rec.keys.include?(User.extjs_primary_key.to_s)
25
+ end
26
+ should "User instance should render to_record containing foreign_key of Person" do
27
+ rec = User.first.to_record
28
+ assn = User.extjs_associations[:person]
29
+ assert rec.keys.include?(assn[:foreign_key])
30
+ end
31
+
32
+ end
33
+
34
+ context "A User with HABTM relationship with Group" do
35
+ setup do
36
+ UserGroup.destroy_all
37
+
38
+ @user = User.first
39
+ UserGroup.create(:user => @user, :group => Group.create(:title => "Merb"))
40
+ UserGroup.create(:user => @user, :group => Group.create(:title => "Rails"))
41
+ end
42
+
43
+ should "Render to_record should return 2 groups" do
44
+ User.extjs_fields(:groups)
45
+ assert @user.to_record["groups"].length == 2
46
+ end
47
+ end
14
48
 
15
- class ModelTest < Test::Unit::TestCase
16
- def test_field_list_for_associations
17
- assert_equal [[:test_parent, :name], :name, :id], TestModel.extjs_fields
49
+ context "A User with Person relationship: User.extjs_fields(:password, :person => [:first, {:last => {'sortDir' => 'ASC'}}])" do
50
+ setup do
51
+ User.extjs_fields(:password, :person => [:first, {:last => {"sortDir" => "ASC"}}])
52
+ @fields = User.extjs_record["fields"]
53
+ end
54
+
55
+ should "User should render a Reader with 4 total fields" do
56
+ assert @fields.count === 4
57
+ end
58
+ should "Reader fields should contain 'password' field" do
59
+ assert @fields.find {|f| f[:name] === "password"}
60
+ end
61
+ should "Reader fields should contain person_id" do
62
+ assns = User.extjs_associations
63
+ assn = assns[:person] || assns["person"]
64
+ assert @fields.find {|f| f[:name] === assns[:person][:foreign_key] }
65
+ end
66
+ should "Reader fields should contain mapped field 'person.first'" do
67
+ assert @fields.find {|f| f[:name] === "person_first" and f["mapping"] === "person.first"}
68
+ end
69
+ should "Reader fields should contain mapped field 'person.last'" do
70
+ assert @fields.find {|f| f[:name] === "person_last" and f["mapping"] === "person.last"}
71
+ end
72
+ should "person.last should have additional configuration 'sortDir' => 'ASC'" do
73
+ assert @fields.find {|f| f[:name] === "person_last" and f["sortDir"] === 'ASC' }
74
+ end
75
+ end
76
+
77
+ context "Fields should render with correct, ExtJS-compatible data-types" do
78
+ setup do
79
+ @fields = DataType.extjs_record["fields"]
80
+ end
81
+
82
+ should "Understand 'string'" do
83
+ assert @fields.find {|f| f[:name] === 'string_column' && f["type"].to_s === 'string'}
84
+ end
85
+ should "Understand 'integer' as 'int'" do
86
+ assert @fields.find {|f| f[:name] === 'integer_column' && f["type"].to_s === 'int'}
87
+ end
88
+ should "Understand 'float'" do
89
+ assert @fields.find {|f| f[:name] === 'float_column' && f["type"].to_s === 'float'}
90
+ end
91
+ should "Understand 'decimal' as 'float'" do # Is this correct??
92
+ assert @fields.find {|f| f[:name] === 'decimal_column' && f["type"].to_s === 'float'}
93
+ end
94
+ should "Understand 'date'" do
95
+ assert @fields.find {|f| f[:name] === 'date_column' && f["type"].to_s === 'date'}
96
+ end
97
+ should "Understand 'datetime' as 'date'" do
98
+ assert @fields.find {|f| f[:name] === 'datetime_column' && f["type"].to_s === 'date'}
99
+ end
100
+ should "Understand 'time' as 'date'" do
101
+ assert @fields.find {|f| f[:name] === 'time_column' && f["type"].to_s === 'date'}
102
+ end
103
+ should "Understand 'boolean'" do
104
+ assert @fields.find {|f| f[:name] === 'boolean_column' && f["type"].to_s === 'boolean'}
105
+ end
106
+ should "Understand NOT NULL" do
107
+ assert @fields.find {|f| f[:name] === 'notnull_column' && f["allowBlank"] === false}
108
+ end
109
+ should "Understand DEFAULT" do # TODO implement this.
110
+ assert @fields.find {|f| f[:name] === 'default_column' && f["default"] === true}
111
+ end
18
112
  end
113
+
114
+
19
115
  end
20
116
 
File without changes
data/test/test_helper.rb CHANGED
@@ -10,5 +10,116 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
10
 
11
11
  require 'extjs-mvc'
12
12
 
13
+ gem 'sqlite3-ruby'
14
+
15
+ begin
16
+ require 'ruby-debug'
17
+ rescue LoadError
18
+ puts "ruby-debug not loaded"
19
+ end
20
+
21
+ ROOT = File.join(File.dirname(__FILE__), '..')
22
+ RAILS_ROOT = ROOT
23
+ RAILS_ENV = "test"
24
+
25
+ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
26
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
27
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
28
+ ActiveRecord::Base.establish_connection(config['test'])
29
+
30
+ ##
31
+ # build User / Person models
32
+ # Move AR-specific stuff to AR test adapter
33
+ #
34
+ class User < ActiveRecord::Base
35
+ include ExtJS::Model
36
+ belongs_to :person
37
+ #has_many :user_groups
38
+ #has_many :groups, :through => :user_groups
39
+ has_and_belongs_to_many :groups, :join_table => :user_groups
40
+
41
+ end
42
+
43
+ class Person < ActiveRecord::Base
44
+ include ExtJS::Model
45
+ end
46
+
47
+ class DataType < ActiveRecord::Base
48
+ include ExtJS::Model
49
+ end
50
+
51
+ class UserGroup < ActiveRecord::Base
52
+ belongs_to :user
53
+ belongs_to :group
54
+ end
55
+
56
+ class Group < ActiveRecord::Base
57
+ has_many :users
58
+ include ExtJS::Model
59
+ end
60
+
13
61
  class Test::Unit::TestCase
14
62
  end
63
+
64
+ ##
65
+ # build simple database
66
+ #
67
+ # people
68
+ #
69
+ ActiveRecord::Base.connection.create_table :users, :force => true do |table|
70
+ table.column :id, :serial
71
+ table.column :person_id, :integer
72
+ table.column :password, :string
73
+ table.column :created_at, :date
74
+ table.column :disabled, :boolean, :default => true
75
+ end
76
+ ##
77
+ # people
78
+ #
79
+ ActiveRecord::Base.connection.create_table :people, :force => true do |table|
80
+ table.column :id, :serial
81
+ table.column :first, :string, :null => false
82
+ table.column :last, :string, :null => false
83
+ table.column :email, :string, :null => false
84
+ end
85
+ ##
86
+ # user_groups, join table
87
+ #
88
+ ActiveRecord::Base.connection.create_table :user_groups, :force => true do |table|
89
+ table.column :user_id, :integer
90
+ table.column :group_id, :integer
91
+ end
92
+
93
+ ##
94
+ # groups
95
+ #
96
+ ActiveRecord::Base.connection.create_table :groups, :force => true do |table|
97
+ table.column :id, :serial
98
+ table.column :title, :string
99
+ end
100
+
101
+ ##
102
+ # Mock a Model for testing data-types
103
+ #
104
+ ActiveRecord::Base.connection.create_table :data_types, :force => true do |table|
105
+ table.column :id, :serial
106
+ table.column :string_column, :string
107
+ table.column :decimal_column, :decimal
108
+ table.column :float_column, :float
109
+ table.column :date_column, :date
110
+ table.column :datetime_column, :datetime
111
+ table.column :time_column, :time
112
+ table.column :email, :string
113
+ table.column :integer_column, :integer
114
+ table.column :notnull_column, :string, :null => false
115
+ table.column :default_column, :boolean, :default => true
116
+ table.column :boolean_column, :boolean
117
+ end
118
+
119
+ ##
120
+ # create a couple of related instances.
121
+ #
122
+ p = Person.create(:first => "Chris", :last => "Scott", :email => "chris@scott.com")
123
+ u = User.create(:password => "1234", :person => p)
124
+
125
+
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.2.7
4
+ version: 0.2.8
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: 2009-11-19 00:00:00 -05:00
12
+ date: 2009-11-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,9 +49,15 @@ files:
49
49
  - lib/model/base.rb
50
50
  - lib/model/data_mapper.rb
51
51
  - lib/model/mongo_mapper.rb
52
+ - lib/test/macros.rb
53
+ - test/active_record_test.rb
52
54
  - test/component_test.rb
53
55
  - test/controller_test.rb
56
+ - test/data_mapper_test.rb
57
+ - test/database.yml
58
+ - test/debug.log
54
59
  - test/model_test.rb
60
+ - test/mongo_mapper.rb
55
61
  - test/store_test.rb
56
62
  - test/test_helper.rb
57
63
  has_rdoc: true