diff --git a/README.rdoc b/README.rdoc
index f6dc943..6e7015f 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -10,7 +10,7 @@ See tutorial http://www.extjs.com/blog/2009/09/30/ext-js-on-rails-a-comprehensiv
% sudo gem install extjs-mvc
Rails Installation:
-In environment.rb,
+In environment.rb,
Rails::Initializer.run do |config|
config.gem "extjs-mvc"
@@ -18,7 +18,7 @@ In environment.rb,
Merb installation:
In config/dependencies.rb, Add extjs-mvc as a new dependency
-
+
dependency "extjs-mvc"
=== An ORM Model mixin: ExtJS::Model
@@ -31,22 +31,22 @@ fields with will be used to render the Ext.data.Record.create field-def
include ExtJS::Model
extjs_fields :exclude => [:password, :password_confirmation]
-
- # OR
+
+ # OR
extjs_fields :name, :description
-
+
# OR
extjs_fields :only => [:name, :description] # actually the same as above
-
+
# OR
extjs_fields :additional => [:computed] # includes all database columns and an additional computed field
-
+
# OR define a column as a Hash
extjs_fields :description, :name => {"sortDir" => "ASC"}, :created_at => {"dateFormat" => "c"}
-
+
# OR render associations, association-fields will have their "mapping" property set automatically
extjs_fields :name, :description, :company => [:name, :description]
-
+
def computed
name.blank? ? login : name
end
@@ -73,7 +73,7 @@ E.g. with the following definition:
extjs_fieldset :grid, fields => [:name, :description, :company => [:name, :description]]
extjs_fieldset :combo, [:full_name]
-
+
def full_name
"#{first_name} #{name}"
end
@@ -83,7 +83,7 @@ You can get store configs for both representations with
User.extjs_record(:grid)
or
User.extjs_record(:combo)
-
+
And the corresponding data for the representations with
User.first.to_record(:grid)
or
@@ -97,7 +97,7 @@ The extjs-mvc Gem includes a framework agnostic Controller mixin which
class UsersController < ActionController::Base
include ExtJS::Controller
end
-
+
=== View Helper: ExtJS::Helpers::Component
usage:
diff --git a/Rakefile b/Rakefile
index 8b87ac9..865c1d6 100644
--- a/Rakefile
+++ b/Rakefile
@@ -13,7 +13,7 @@ begin
gem.add_development_dependency "shoulda"
gem.add_development_dependency "mocha"
gem.add_development_dependency "extlib"
-
+
gem.test_files = []
gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
diff --git a/lib/extjs-mvc.rb b/lib/extjs-mvc.rb
index 7e36112..40725b2 100644
--- a/lib/extjs-mvc.rb
+++ b/lib/extjs-mvc.rb
@@ -6,9 +6,9 @@ class MVC
cattr_accessor :success_property
cattr_accessor :message_property
cattr_accessor :root
-
+
require 'model/base'
-
+
# Detect orm, include appropriate mixin.
if defined?(ActiveRecord)
require 'model/active_record'
diff --git a/lib/extjs/data/store.rb b/lib/extjs/data/store.rb
index d42d306..a6fe198 100644
--- a/lib/extjs/data/store.rb
+++ b/lib/extjs/data/store.rb
@@ -7,25 +7,25 @@ class Store
def initialize(*params)
options = params.extract_options!
-
+
@config = options[:config] || {}
@format = options[:format] || 'json'
@fieldset = options[:fieldset] || :default
@schema = options[:schema]
@proxy = options[:proxy] || 'http'
@writer = options[:writer]
- @type = (options[:type].nil?) ? @proxy === 'direct' ? 'Ext.data.DirectStore' : "Ext.data.#{@format.capitalize}Store" : options[:type]
-
+ @type = (options[:type].nil?) ? @proxy === 'direct' ? 'Ext.data.DirectStore' : "Ext.data.#{@format.capitalize}Store" : options[:type]
+
@controller = self.class.get_controller(options[:controller])
@model = self.class.get_model(options[:controller], options[:model])
# Merge Reader/Proxy config
@config.merge!(reader)
@config.merge!(proxy)
-
+
@config["baseParams"] = {} if @config["baseParams"].nil?
@config["baseParams"].update("fieldset" => @fieldset)
-
+
@config["format"] = @format
# Set storeId implicitly based upon Model name if not set explicitly
@@ -69,7 +69,7 @@ def render(script_tag = true)
""
end
end
-
+
private
def self.get_controller(name)
@@ -83,7 +83,7 @@ def self.get_controller(name)
throw NameError.new("ExtJS::Store failed with an unknown controller named '#{name.to_s}'")
end
end
-
+
def self.get_model(controller, model)
unless model.class == Class
begin
@@ -98,7 +98,7 @@ def self.get_model(controller, model)
end
model
end
-
+
def proxy
proxy = {}
if @proxy === 'direct'
@@ -117,15 +117,15 @@ def proxy
end
proxy
end
-
- def reader
+
+ def reader
{
"successProperty" => @controller.extjs_success_property,
"root" => @controller.extjs_root,
"messageProperty" => @controller.extjs_message_property
}.merge(@schema || @model.extjs_record(@fieldset))
end
-
-
+
+
end
end
diff --git a/lib/model/active_record.rb b/lib/model/active_record.rb
index 3b24cef..164c77a 100644
--- a/lib/model/active_record.rb
+++ b/lib/model/active_record.rb
@@ -4,19 +4,19 @@
module ExtJS
module Model
module ClassMethods
-
+
def extjs_primary_key
self.primary_key.to_sym
end
-
+
def extjs_column_names
self.column_names.map(&:to_sym)
end
-
+
def extjs_columns_hash
self.columns_hash.symbolize_keys
end
-
+
##
# determine if supplied Column object is nullable
# @param {ActiveRecord::ConnectionAdapters::Column}
@@ -28,7 +28,7 @@ def extjs_allow_blank(col)
# new records have no id and thus cannot be valid
col.name == self.primary_key || col.null
end
-
+
##
# returns the default value
# @param {ActiveRecord::ConnectionAdapters::Column}
@@ -37,7 +37,7 @@ def extjs_allow_blank(col)
def extjs_default(col)
col.default
end
-
+
##
# returns the corresponding column name of the type column for a polymorphic association
# @param {String/Symbol} the id column name for this association
@@ -45,7 +45,7 @@ def extjs_default(col)
def extjs_polymorphic_type(id_column_name)
id_column_name.to_s.gsub(/_id\Z/, '_type').to_sym
end
-
+
##
# determine datatype of supplied Column object
# @param {ActiveRecord::ConnectionAdapters::Column}
@@ -65,7 +65,7 @@ def extjs_type(col)
end
type
end
-
+
##
# return a simple, normalized list of AR associations having the :name, :type and association class
# @return {Array}
@@ -74,8 +74,8 @@ def extjs_associations
@extjs_associations ||= self.reflections.inject({}) do |memo, (key, assn)|
type = (assn.macro === :has_many || assn.macro === :has_and_belongs_to_many) ? :many : assn.macro
memo[key.to_sym] = {
- :name => key.to_sym,
- :type => type,
+ :name => key.to_sym,
+ :type => type,
:class => assn.options[:polymorphic] ? nil : assn.class_name.constantize,
:foreign_key => assn.association_foreign_key.to_sym,
:is_polymorphic => !!assn.options[:polymorphic]
diff --git a/lib/model/base.rb b/lib/model/base.rb
index 61e012e..0740aea 100644
--- a/lib/model/base.rb
+++ b/lib/model/base.rb
@@ -1,6 +1,6 @@
module ExtJS
module Model
-
+
def self.included(model)
model.send(:extend, ClassMethods)
model.send(:include, InstanceMethods)
@@ -18,7 +18,7 @@ def self.included(model)
# InstanceMethods
#
module InstanceMethods
-
+
##
# Converts a model instance to a record compatible with ExtJS
#
@@ -29,7 +29,7 @@ module InstanceMethods
#
# All these are valid calls:
#
- # user.to_record # returns record for :default fieldset
+ # user.to_record # returns record for :default fieldset
# # (fieldset is autmatically defined, if not set)
#
# user.to_record :fieldset # returns record for :fieldset fieldset
@@ -37,36 +37,36 @@ module InstanceMethods
#
# user.to_record :fields => [:id, :password]
# # returns record for the fields 'id' and 'password'
- #
+ #
# For even more valid options for this method (which all should not be neccessary to use)
# have a look at ExtJS::Model::Util.extract_fieldset_and_options
def to_record(*params)
fieldset, options = Util.extract_fieldset_and_options params
-
+
fields = []
if options[:fields].empty?
fields = self.class.extjs_get_fields_for_fieldset(fieldset)
else
fields = self.class.process_fields(*options[:fields])
end
-
+
assns = self.class.extjs_associations
pk = self.class.extjs_primary_key
-
+
# build the initial field data-hash
data = {pk => self.send(pk)}
-
+
fields.each do |field|
next if data.has_key? field[:name] # already processed (e.g. explicit mentioning of :id)
-
+
value = nil
if association_reflection = assns[field[:name]] # if field is an association
association = self.send(field[:name])
-
+
# skip this association if we already visited it
# otherwise we could end up in a cyclic reference
next if options[:visited_classes].include? association.class
-
+
case association_reflection[:type]
when :belongs_to, :has_one
if association.respond_to? :to_record
@@ -74,7 +74,7 @@ def to_record(*params)
if assn_fields.nil?
assn_fields = association.class.extjs_get_fields_for_fieldset(field.fetch(:fieldset, fieldset))
end
-
+
value = association.to_record :fields => assn_fields,
:visited_classes => options[:visited_classes] + [self.class]
else
@@ -103,7 +103,7 @@ def to_record(*params)
data
end
end
-
+
##
# ClassMethods
#
@@ -119,7 +119,7 @@ module ClassMethods
#
# All these are valid calls:
#
- # User.extjs_record # returns record config for :default fieldset
+ # User.extjs_record # returns record config for :default fieldset
# # (fieldset is autmatically defined, if not set)
#
# User.extjs_record :fieldset # returns record config for :fieldset fieldset
@@ -127,57 +127,57 @@ module ClassMethods
#
# User.extjs_record :fields => [:id, :password]
# # returns record config for the fields 'id' and 'password'
- #
+ #
# For even more valid options for this method (which all should not be neccessary to use)
# have a look at ExtJS::Model::Util.extract_fieldset_and_options
def extjs_record(*params)
fieldset, options = Util.extract_fieldset_and_options params
-
+
if options[:fields].empty?
fields = self.extjs_get_fields_for_fieldset(fieldset)
else
fields = self.process_fields(*options[:fields])
end
-
+
associations = self.extjs_associations
columns = self.extjs_columns_hash
pk = self.extjs_primary_key
rs = []
-
+
fields.each do |field|
field = Marshal.load(Marshal.dump(field)) # making a deep copy
-
- if col = columns[field[:name]] # <-- column on this model
- rs << self.extjs_field(field, col)
+
+ if col = columns[field[:name]] # <-- column on this model
+ rs << self.extjs_field(field, col)
elsif assn = associations[field[:name]]
# skip this association if we already visited it
# otherwise we could end up in a cyclic reference
next if options[:visited_classes].include? assn[:class]
-
+
assn_fields = field[:fields]
if assn[:class].respond_to?(:extjs_record) # <-- exec extjs_record on assn Model.
if assn_fields.nil?
assn_fields = assn[:class].extjs_get_fields_for_fieldset(field.fetch(:fieldset, fieldset))
end
-
+
record = assn[:class].extjs_record(field.fetch(:fieldset, fieldset), { :visited_classes => options[:visited_classes] + [self], :fields => assn_fields})
- rs.concat(record[:fields].collect { |assn_field|
+ rs.concat(record[:fields].collect { |assn_field|
self.extjs_field(assn_field, :parent_trail => field[:name], :mapping => field[:name], :allowBlank => true) # <-- allowBlank on associated data?
})
elsif assn_fields # <-- :parent => [:id, :name, :sub => [:id, :name]]
field_collector = Proc.new do |parent_trail, mapping, assn_field|
if assn_field.is_a?(Hash) && assn_field.keys.size == 1 && assn_field.keys[0].is_a?(Symbol) && assn_field.values[0].is_a?(Array)
- field_collector.call(parent_trail.to_s + self.extjs_parent_trail_template.call(assn_field.keys.first), "#{mapping}.#{assn_field.keys.first}", assn_field.values.first)
+ field_collector.call(parent_trail.to_s + self.extjs_parent_trail_template.call(assn_field.keys.first), "#{mapping}.#{assn_field.keys.first}", assn_field.values.first)
else
self.extjs_field(assn_field, :parent_trail => parent_trail, :mapping => mapping, :allowBlank => true)
end
end
rs.concat(assn_fields.collect { |assn_field| field_collector.call(field[:name], field[:name], assn_field) })
- else
+ else
rs << extjs_field(field)
end
-
+
# attach association's foreign_key if not already included.
if columns.has_key?(assn[:foreign_key]) && !rs.any? { |r| r[:name] == assn[:foreign_key] }
rs << extjs_field({:name => assn[:foreign_key]}, columns[assn[:foreign_key]])
@@ -193,13 +193,13 @@ def extjs_record(*params)
rs << extjs_field(field)
end
end
-
+
return {
:fields => rs,
:idProperty => pk
}
end
-
+
##
# meant to be used within a Model to define the extjs record fields.
# eg:
@@ -216,7 +216,7 @@ def extjs_fieldset(*params)
var_name = :"@extjs_fieldsets__#{fieldset}"
self.instance_variable_set( var_name, self.process_fields(*options[:fields]) )
end
-
+
def extjs_get_fields_for_fieldset(fieldset)
var_name = :"@extjs_fieldsets__#{fieldset}"
super_value = nil
@@ -228,7 +228,7 @@ def extjs_get_fields_for_fieldset(fieldset)
end
super_value || self.instance_variable_get( var_name )
end
-
+
##
# shortcut to define the default fieldset. For backwards-compatibility.
#
@@ -237,9 +237,9 @@ def extjs_fields(*params)
:fields => params
})
end
-
+
##
- # Prepare a field configuration list into a normalized array of Hashes, {:name => "field_name"}
+ # Prepare a field configuration list into a normalized array of Hashes, {:name => "field_name"}
# @param {Mixed} params
# @return {Array} of Hashes
#
@@ -255,11 +255,11 @@ def process_fields(*params)
return self.process_fields(*options[:only])
end
end
-
+
params = self.extjs_column_names if params.empty?
-
+
associations = extjs_associations
-
+
params.each do |f|
if f.kind_of?(Hash)
if f.keys.size == 1 && f.keys[0].is_a?(Symbol) && f.values[0].is_a?(Array) # {:association => [:field1, :field2]}
@@ -279,16 +279,16 @@ def process_fields(*params)
fields << {:name => f.to_sym}
end
end
-
+
fields
end
-
+
##
# Render a column-config object
# @param {Hash/Column} field Field-configuration Hash, probably has :name already set and possibly Ext.data.Field options.
# @param {ORM Column Object from AR, DM or MM}
#
- def extjs_field(field, config=nil)
+ def extjs_field(field, config=nil)
if config.kind_of? Hash
if config.has_key?(:mapping) && config.has_key?(:parent_trail)
field.update( # <-- We use a template for rendering mapped field-names.
@@ -303,8 +303,8 @@ def extjs_field(field, config=nil)
:type => self.extjs_type(config),
:defaultValue => self.extjs_default(config)
)
- field[:dateFormat] = "c" if field[:type] === "date" && field[:dateFormat].nil? # <-- ugly hack for date
- end
+ field[:dateFormat] = "c" if field[:type] === "date" && field[:dateFormat].nil? # <-- ugly hack for date
+ end
field.update(:type => "auto") if field[:type].nil?
# convert Symbol values to String values
field.keys.each do |k|
@@ -332,11 +332,11 @@ def extjs_field(field, config=nil)
# @extjs_used_associations
# end
end
-
+
module Util
-
+
##
- # returns the fieldset from the arguments and normalizes the options.
+ # returns the fieldset from the arguments and normalizes the options.
# @return [{Symbol}, {Hash}]
def self.extract_fieldset_and_options arguments
orig_args = arguments
diff --git a/lib/model/data_mapper.rb b/lib/model/data_mapper.rb
index 24bbd6c..da9af8e 100644
--- a/lib/model/data_mapper.rb
+++ b/lib/model/data_mapper.rb
@@ -5,15 +5,15 @@
module ExtJS
module Model
module ClassMethods
-
+
def extjs_primary_key
self.key.first.name
end
-
+
def extjs_column_names
self.properties.collect {|p| p.name.to_s }
end
-
+
def extjs_columns_hash
if @extjs_columns_hash.nil?
@extjs_columns_hash = {}
@@ -23,11 +23,11 @@ def extjs_columns_hash
end
@extjs_columns_hash
end
-
+
def extjs_allow_blank(col)
(col === self.key.first) ? true : col.nullable?
end
-
+
def extjs_type(col)
type = ((col.type.respond_to?(:primitive)) ? col.type.primitive : col.type).to_s
case type
@@ -43,14 +43,14 @@ def extjs_type(col)
type = "auto"
end
end
-
+
def extjs_associations
- if @extjs_associations.nil?
+ if @extjs_associations.nil?
@extjs_associations = {}
self.relationships.keys.each do |key|
assn = self.relationships[key]
@extjs_associations[key.to_sym] = {
- :name => key,
+ :name => key,
:type => type = (assn.options[:max].nil? && assn.options[:min].nil?) ? :belongs_to : (assn.options[:max] > 1) ? :many : nil ,
:class => assn.parent_model,
:foreign_key => assn.child_key.first.name,
diff --git a/lib/model/mongo_mapper.rb b/lib/model/mongo_mapper.rb
index 4ed6974..fea5ce6 100644
--- a/lib/model/mongo_mapper.rb
+++ b/lib/model/mongo_mapper.rb
@@ -1,7 +1,7 @@
##
# MongoMapper adapter to ExtJS::Model mixin
#
-
+
module ExtJS
module Model
##
@@ -53,11 +53,11 @@ def extjs_type(col)
def extjs_allow_blank(col)
(col.name == '_id') || (col.options[:required] != true)
end
-
+
def extjs_default(col)
col.default_value
end
-
+
end
end
end
diff --git a/test/app/config/application.rb b/test/app/config/application.rb
index bb9430f..0742f33 100644
--- a/test/app/config/application.rb
+++ b/test/app/config/application.rb
@@ -7,44 +7,44 @@
gem 'sqlite3-ruby'
class Test::App
-
+
attr_reader :models
-
+
def initialize(orm = :active_record)
@orm = orm
@config = YAML::load(IO.read("#{ROOT}/config/database.yml"))
-
+
# Load ORM
send("boot_#{orm.to_s}")
-
+
load_models
require 'db/schema'
-
+
end
-
+
##
# Reset a model's @extjs_fieldsets
#
def clean_all
@models.map { |klass| clean klass }
end
-
-
+
+
private
-
+
def boot_active_record
ActiveRecord::Base.establish_connection(@config['test'])
end
-
+
def boot_mongo_mapper
-
+
end
-
+
def boot_data_mapper
-
+
end
-
+
##
# Do a dir on /models and constantize each filename
#
@@ -52,13 +52,13 @@ def load_models
@models = []
# Load Models and Schema for corresponding orm
re = /^.*\/(.*).rb$/
- Dir["#{ROOT}/models/#{@orm.to_s}/*"].each { |c|
- require c
+ Dir["#{ROOT}/models/#{@orm.to_s}/*"].each { |c|
+ require c
match = c.match(re)
@models << Extlib::Inflection.constantize(Extlib::Inflection.camelize(match[1])) if match
}
end
-
+
def clean klass
klass.instance_variables.each do |var_name|
if /\A@extjs_fieldsets__/ =~ var_name.to_s
@@ -66,5 +66,5 @@ def clean klass
end
end
end
-
+
end
\ No newline at end of file
diff --git a/test/app/models/active_record/user.rb b/test/app/models/active_record/user.rb
index ddda07b..65c79df 100644
--- a/test/app/models/active_record/user.rb
+++ b/test/app/models/active_record/user.rb
@@ -1,6 +1,6 @@
class User < ActiveRecord::Base
include ExtJS::Model
belongs_to :person
-
+
has_and_belongs_to_many :groups, :join_table => :user_groups
end
\ No newline at end of file
diff --git a/test/model_test.rb b/test/model_test.rb
index 44a04f9..f86a4ce 100644
--- a/test/model_test.rb
+++ b/test/model_test.rb
@@ -15,19 +15,19 @@ class << self
def extjs_allow_blank(col)
true
end
-
+
def extjs_default(col)
nil
end
-
+
def extjs_type(col)
nil
end
-
+
def extjs_column_names
[:one, :two, :three_id]
end
-
+
def extjs_columns_hash
{
:one => {},
@@ -35,15 +35,15 @@ def extjs_columns_hash
:three_id => {}
}
end
-
+
def extjs_polymorphic_type(id_column_name)
id_column_name.to_s.gsub(/_id\Z/, '_type').to_sym
end
-
+
def extjs_primary_key
:id
end
-
+
def extjs_associations
{
:three => {
@@ -91,19 +91,19 @@ class ModelTest < Test::Unit::TestCase
assn = User.extjs_associations[:person]
assert rec.keys.include?(assn[:foreign_key])
end
-
+
end
-
+
context "A User with HABTM relationship with Group" do
setup do
App.clean_all
UserGroup.destroy_all
-
+
@user = User.first
UserGroup.create(:user => @user, :group => Group.create(:title => "Merb"))
UserGroup.create(:user => @user, :group => Group.create(:title => "Rails"))
end
-
+
should "Render to_record should return 2 groups" do
User.extjs_fields(:groups)
assert @user.to_record[:groups].length == 2
@@ -116,7 +116,7 @@ class ModelTest < Test::Unit::TestCase
User.extjs_fields(:password, {:person => [:first, {:last => {:sortDir => "ASC"}}]})
@fields = User.extjs_record[:fields]
end
-
+
should "User should render a Reader with 4 total fields" do
assert @fields.count === 4
end
@@ -124,7 +124,7 @@ class ModelTest < Test::Unit::TestCase
assert_array_has_item(@fields, 'has password field') {|f| f[:name] === "password"}
end
should "Reader fields should contain person_id" do
- assns = User.extjs_associations
+ assns = User.extjs_associations
assn = assns[:person]
assert_array_has_item(@fields, 'has foreign key person_id') {|f| f[:name] === assns[:person][:foreign_key].to_s }
end
@@ -137,7 +137,7 @@ class ModelTest < Test::Unit::TestCase
should "person.last should have additional configuration 'sortDir' => 'ASC'" do
assert_array_has_item(@fields, 'has person.last with sortDir') {|f| f[:name] === "person_last" and f[:sortDir] === 'ASC' }
end
-
+
should "produce a valid to_record record" do
person = Person.create!(:first => 'first', :last => 'last', :email => 'email')
user = User.create!(:person_id => person.id, :password => 'password')
@@ -149,7 +149,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal('first', record[:person][:first])
end
end
-
+
context "User with standard Person association" do
setup do
App.clean_all
@@ -174,7 +174,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal('first', record[:person][:first])
end
end
-
+
context "Person with User association (has_one relationship)" do
setup do
App.clean_all
@@ -196,7 +196,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal('password', record[:user][:password])
end
end
-
+
context "Person with User association (has_one/belongs_to relationship) cyclic reference" do
setup do
App.clean_all
@@ -216,13 +216,13 @@ class ModelTest < Test::Unit::TestCase
assert_equal(user.id, record[:user][:id])
end
end
-
+
context "Fields should render with correct, ExtJS-compatible data-types" do
setup do
App.clean_all
@fields = DataType.extjs_record[:fields]
end
-
+
should "Understand 'string'" do
assert_array_has_item(@fields, 'has string_column with string') {|f| f[:name] == 'string_column' and f[:type] == 'string'}
end
@@ -254,23 +254,23 @@ class ModelTest < Test::Unit::TestCase
assert_array_has_item(@fields, 'has default_column with defaultValue == true') {|f| f[:name] == 'default_column' and f[:defaultValue] === true}
end
end
-
+
context "polymorphic associations" do
setup do
App.clean_all
end
-
+
should "return nil as class for a polymorphic relation" do
assert_equal(nil, Address.extjs_associations[:addressable][:class])
end
-
+
should "create a proper default store config" do
Address.extjs_fields
fields = Address.extjs_record[:fields]
assert_array_has_item(fields, 'has addressable_id') {|f| f[:name] === 'addressable_id' && !f[:mapping] }
assert_array_has_item(fields, 'addressable_type') {|f| f[:name] === 'addressable_type' && !f[:mapping] }
end
-
+
should "create the right store config when including members of the polymorphic association" do
Address.extjs_fields :street, :addressable => [:name]
fields = Address.extjs_record[:fields]
@@ -278,7 +278,7 @@ class ModelTest < Test::Unit::TestCase
assert_array_has_item(fields, "has addressable_id") {|f| f[:name] === 'addressable_id' && !f[:mapping] }
assert_array_has_item(fields, "has addressable_type") {|f| f[:name] === 'addressable_type' && !f[:mapping] }
end
-
+
should "fill in the right values for to_record" do
Address.extjs_fields :street, :addressable => [:name]
location = Location.create!(:name => 'Home')
@@ -291,12 +291,12 @@ class ModelTest < Test::Unit::TestCase
assert_equal("Main Street 1", record[:street])
end
end
-
+
context "single table inheritance" do
setup do
App.clean_all
end
-
+
should "fieldsets should be accessible from descendants" do
Location.extjs_fieldset :on_location, [:street]
fields = House.extjs_record(:on_location)[:fields]
@@ -311,7 +311,7 @@ class ModelTest < Test::Unit::TestCase
assert_array_has_item(fields, 'has name') {|f| f[:name] === 'name' }
end
end
-
+
context "ExtJS::Model::Util" do
context "#extract_fieldset_and_options default" do
setup do
@@ -338,7 +338,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal([:one, :two, :three], @fields)
end
end
-
+
context "#extract_fieldset_and_options with explicit fieldset definition and hash with fields" do
setup do
@fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options [:explicit, {:fields => [:one, :two, :three]}]
@@ -351,7 +351,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal([:one, :two, :three], @fields)
end
end
-
+
context "#extract_fieldset_and_options with only a hash" do
setup do
@fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options [{:fieldset => :explicit, :fields => [:one, :two, :three]}]
@@ -364,7 +364,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal([:one, :two, :three], @fields)
end
end
-
+
context "#extract_fieldset_and_options edge cases" do
should "called without arguments" do
@fieldset, @options = ExtJS::Model::Util.extract_fieldset_and_options []
@@ -386,9 +386,9 @@ class ModelTest < Test::Unit::TestCase
end
end
end
-
+
context "ExtJS::Model::ClassMethods" do
-
+
context "#process_fields" do
should "handle a simple Array of Symbols" do
@fields = BogusModel.process_fields :one, :two, :three
@@ -401,8 +401,8 @@ class ModelTest < Test::Unit::TestCase
should "handle a mixed Array where a middle item is a Hash" do
@fields = BogusModel.process_fields :one, {:two => [:two_one, :two_two]}, :three
assert_equal([
- {:name => :one},
- {:name => :two, :fields => [{:name => :two_one}, {:name => :two_two}]},
+ {:name => :one},
+ {:name => :two, :fields => [{:name => :two_one}, {:name => :two_two}]},
{:name => :three}], @fields)
end
should "handle option :only" do
@@ -416,7 +416,7 @@ class ModelTest < Test::Unit::TestCase
should "handle option :additional" do
@fields = BogusModel.process_fields :additional => [:additional_attribute]
assert_equal([{:name => :one}, {:name => :two}, {:name => :three_id}, {:name => :additional_attribute}], @fields)
-
+
end
should "handle {:field => {:sortDir => 'ASC'}}" do
@fields = BogusModel.process_fields({:field => {:sortDir => 'ASC'}})
@@ -434,7 +434,7 @@ class ModelTest < Test::Unit::TestCase
assert_raise(ArgumentError) { @fields = BogusModel.process_fields(:one, {:nme => :field,:sortDir => 'ASC'}) }
end
end
-
+
context "#extjs_field" do
should "type gets set to 'auto' when not present" do
@field = BogusModel.extjs_field({:name => :test})
@@ -449,7 +449,7 @@ class ModelTest < Test::Unit::TestCase
end
end
-
+
context "#extjs_field with ORM config" do
should "set allowBlank" do
BogusModel.expects(:extjs_allow_blank).returns(false)
@@ -477,7 +477,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal('not-c', @field[:dateFormat])
end
end
-
+
context "#extjs_field with Hash config" do
should "set correct name and mapping" do
@field = BogusModel.extjs_field({:name => :son}, {:mapping => 'grandfather.father', :parent_trail => 'grandfather_father'})
@@ -489,7 +489,7 @@ class ModelTest < Test::Unit::TestCase
assert_equal('ASC', @field[:sortDir])
end
end
-
+
context "#extjs_get_fields_for_fieldset" do
should "return full list of columns for fieldset that was not defined, yet" do
@fields = BogusModel.extjs_get_fields_for_fieldset :not_there
@@ -521,6 +521,6 @@ def assert_array_has_item array, item_description, &blk
def assert_array_has_not_item array, item_description, &blk
assert !array.find {|i| blk.call(i) }, "The array #{array.inspect} should not #{item_description} but it does"
end
-
+
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 43f3637..ef4141f 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -24,7 +24,7 @@
#
App = Test::App.new(:active_record)
-#FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
+#FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
class Test::Unit::TestCase