Normalise line endings.
This commit is contained in:
parent
3e67d08c13
commit
a36185b22f
48 changed files with 2078 additions and 2078 deletions
|
@ -1,5 +1,5 @@
|
|||
class Article < ActiveRecord::Base
|
||||
has_many :readings
|
||||
has_many :users, :through => :readings
|
||||
end
|
||||
|
||||
class Article < ActiveRecord::Base
|
||||
has_many :readings
|
||||
has_many :users, :through => :readings
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
first:
|
||||
id: 1
|
||||
name: Article One
|
||||
second:
|
||||
id: 2
|
||||
first:
|
||||
id: 1
|
||||
name: Article One
|
||||
second:
|
||||
id: 2
|
||||
name: Article Two
|
|
@ -1,7 +1,7 @@
|
|||
class Product < ActiveRecord::Base
|
||||
set_primary_keys :id # redundant
|
||||
has_many :product_tariffs, :foreign_key => :product_id
|
||||
has_one :product_tariff, :foreign_key => :product_id
|
||||
|
||||
has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
end
|
||||
class Product < ActiveRecord::Base
|
||||
set_primary_keys :id # redundant
|
||||
has_many :product_tariffs, :foreign_key => :product_id
|
||||
has_one :product_tariff, :foreign_key => :product_id
|
||||
|
||||
has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class ProductTariff < ActiveRecord::Base
|
||||
set_primary_keys :product_id, :tariff_id, :tariff_start_date
|
||||
belongs_to :product, :foreign_key => :product_id
|
||||
belongs_to :tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
end
|
||||
class ProductTariff < ActiveRecord::Base
|
||||
set_primary_keys :product_id, :tariff_id, :tariff_start_date
|
||||
belongs_to :product, :foreign_key => :product_id
|
||||
belongs_to :tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
first_flat:
|
||||
product_id: 1
|
||||
tariff_id: 1
|
||||
tariff_start_date: <%= Date.today.to_s(:db) %>
|
||||
first_free:
|
||||
product_id: 1
|
||||
tariff_id: 2
|
||||
tariff_start_date: <%= Date.today.to_s(:db) %>
|
||||
second_free:
|
||||
product_id: 2
|
||||
tariff_id: 2
|
||||
tariff_start_date: <%= Date.today.to_s(:db) %>
|
||||
first_flat:
|
||||
product_id: 1
|
||||
tariff_id: 1
|
||||
tariff_start_date: <%= Date.today.to_s(:db) %>
|
||||
first_free:
|
||||
product_id: 1
|
||||
tariff_id: 2
|
||||
tariff_start_date: <%= Date.today.to_s(:db) %>
|
||||
second_free:
|
||||
product_id: 2
|
||||
tariff_id: 2
|
||||
tariff_start_date: <%= Date.today.to_s(:db) %>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
first_product:
|
||||
id: 1
|
||||
name: Product One
|
||||
second_product:
|
||||
id: 2
|
||||
first_product:
|
||||
id: 1
|
||||
name: Product One
|
||||
second_product:
|
||||
id: 2
|
||||
name: Product Two
|
|
@ -1,4 +1,4 @@
|
|||
class Reading < ActiveRecord::Base
|
||||
belongs_to :article
|
||||
belongs_to :user
|
||||
end
|
||||
class Reading < ActiveRecord::Base
|
||||
belongs_to :article
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
santiago_first:
|
||||
id: 1
|
||||
user_id: 1
|
||||
article_id: 1
|
||||
rating: 4
|
||||
santiago_second:
|
||||
id: 2
|
||||
user_id: 1
|
||||
article_id: 2
|
||||
santiago_first:
|
||||
id: 1
|
||||
user_id: 1
|
||||
article_id: 1
|
||||
rating: 4
|
||||
santiago_second:
|
||||
id: 2
|
||||
user_id: 1
|
||||
article_id: 2
|
||||
rating: 5
|
|
@ -1,7 +1,7 @@
|
|||
class ReferenceCode < ActiveRecord::Base
|
||||
set_primary_keys :reference_type_id, :reference_code
|
||||
|
||||
belongs_to :reference_type, :foreign_key => "reference_type_id"
|
||||
|
||||
validates_presence_of :reference_code, :code_label, :abbreviation
|
||||
end
|
||||
class ReferenceCode < ActiveRecord::Base
|
||||
set_primary_keys :reference_type_id, :reference_code
|
||||
|
||||
belongs_to :reference_type, :foreign_key => "reference_type_id"
|
||||
|
||||
validates_presence_of :reference_code, :code_label, :abbreviation
|
||||
end
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
name_prefix_mr:
|
||||
reference_type_id: 1
|
||||
reference_code: 1
|
||||
code_label: MR
|
||||
abbreviation: Mr
|
||||
name_prefix_mrs:
|
||||
reference_type_id: 1
|
||||
reference_code: 2
|
||||
code_label: MRS
|
||||
abbreviation: Mrs
|
||||
name_prefix_ms:
|
||||
reference_type_id: 1
|
||||
reference_code: 3
|
||||
code_label: MS
|
||||
abbreviation: Ms
|
||||
|
||||
gender_male:
|
||||
reference_type_id: 2
|
||||
reference_code: 1
|
||||
code_label: MALE
|
||||
abbreviation: Male
|
||||
gender_female:
|
||||
reference_type_id: 2
|
||||
reference_code: 2
|
||||
code_label: FEMALE
|
||||
abbreviation: Female
|
||||
|
||||
name_prefix_mr:
|
||||
reference_type_id: 1
|
||||
reference_code: 1
|
||||
code_label: MR
|
||||
abbreviation: Mr
|
||||
name_prefix_mrs:
|
||||
reference_type_id: 1
|
||||
reference_code: 2
|
||||
code_label: MRS
|
||||
abbreviation: Mrs
|
||||
name_prefix_ms:
|
||||
reference_type_id: 1
|
||||
reference_code: 3
|
||||
code_label: MS
|
||||
abbreviation: Ms
|
||||
|
||||
gender_male:
|
||||
reference_type_id: 2
|
||||
reference_code: 1
|
||||
code_label: MALE
|
||||
abbreviation: Male
|
||||
gender_female:
|
||||
reference_type_id: 2
|
||||
reference_code: 2
|
||||
code_label: FEMALE
|
||||
abbreviation: Female
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
class ReferenceType < ActiveRecord::Base
|
||||
set_primary_key :reference_type_id
|
||||
has_many :reference_codes, :foreign_key => "reference_type_id"
|
||||
|
||||
validates_presence_of :type_label, :abbreviation
|
||||
validates_uniqueness_of :type_label
|
||||
end
|
||||
class ReferenceType < ActiveRecord::Base
|
||||
set_primary_key :reference_type_id
|
||||
has_many :reference_codes, :foreign_key => "reference_type_id"
|
||||
|
||||
validates_presence_of :type_label, :abbreviation
|
||||
validates_uniqueness_of :type_label
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
name_prefix:
|
||||
reference_type_id: 1
|
||||
type_label: NAME_PREFIX
|
||||
abbreviation: Name Prefix
|
||||
|
||||
gender:
|
||||
reference_type_id: 2
|
||||
type_label: GENDER
|
||||
abbreviation: Gender
|
||||
name_prefix:
|
||||
reference_type_id: 1
|
||||
type_label: NAME_PREFIX
|
||||
abbreviation: Name Prefix
|
||||
|
||||
gender:
|
||||
reference_type_id: 2
|
||||
type_label: GENDER
|
||||
abbreviation: Gender
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Suburb < ActiveRecord::Base
|
||||
set_primary_keys :city_id, :suburb_id
|
||||
has_many :streets, :foreign_key => [:city_id, :suburb_id]
|
||||
has_many :first_streets, :foreign_key => [:city_id, :suburb_id],
|
||||
:class_name => 'Street', :conditions => "streets.name = 'First Street'"
|
||||
class Suburb < ActiveRecord::Base
|
||||
set_primary_keys :city_id, :suburb_id
|
||||
has_many :streets, :foreign_key => [:city_id, :suburb_id]
|
||||
has_many :first_streets, :foreign_key => [:city_id, :suburb_id],
|
||||
:class_name => 'Street', :conditions => "streets.name = 'First Street'"
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
first:
|
||||
city_id: 1
|
||||
suburb_id: 1
|
||||
name: First Suburb
|
||||
second:
|
||||
city_id: 2
|
||||
suburb_id: 1
|
||||
name: Second Suburb
|
||||
first:
|
||||
city_id: 1
|
||||
suburb_id: 1
|
||||
name: First Suburb
|
||||
second:
|
||||
city_id: 2
|
||||
suburb_id: 1
|
||||
name: Second Suburb
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
class Tariff < ActiveRecord::Base
|
||||
set_primary_keys [:tariff_id, :start_date]
|
||||
has_many :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
has_one :product_tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
has_many :products, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
end
|
||||
class Tariff < ActiveRecord::Base
|
||||
set_primary_keys [:tariff_id, :start_date]
|
||||
has_many :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
has_one :product_tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
has_many :products, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
flat:
|
||||
tariff_id: 1
|
||||
start_date: <%= Date.today.to_s(:db) %>
|
||||
amount: 50
|
||||
free:
|
||||
tariff_id: 2
|
||||
start_date: <%= Date.today.to_s(:db) %>
|
||||
amount: 0
|
||||
flat_future:
|
||||
tariff_id: 1
|
||||
start_date: <%= Date.today.next.to_s(:db) %>
|
||||
amount: 100
|
||||
flat:
|
||||
tariff_id: 1
|
||||
start_date: <%= Date.today.to_s(:db) %>
|
||||
amount: 50
|
||||
free:
|
||||
tariff_id: 2
|
||||
start_date: <%= Date.today.to_s(:db) %>
|
||||
amount: 0
|
||||
flat_future:
|
||||
tariff_id: 1
|
||||
start_date: <%= Date.today.next.to_s(:db) %>
|
||||
amount: 100
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
class User < ActiveRecord::Base
|
||||
has_many :readings
|
||||
has_many :articles, :through => :readings
|
||||
has_many :comments, :as => :person
|
||||
has_many :hacks, :through => :comments, :source => :hack
|
||||
|
||||
def find_custom_articles
|
||||
articles.find(:all, :conditions => ["name = ?", "Article One"])
|
||||
end
|
||||
end
|
||||
class User < ActiveRecord::Base
|
||||
has_many :readings
|
||||
has_many :articles, :through => :readings
|
||||
has_many :comments, :as => :person
|
||||
has_many :hacks, :through => :comments, :source => :hack
|
||||
|
||||
def find_custom_articles
|
||||
articles.find(:all, :conditions => ["name = ?", "Article One"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
santiago:
|
||||
id: 1
|
||||
name: Santiago
|
||||
drnic:
|
||||
id: 2
|
||||
santiago:
|
||||
id: 1
|
||||
name: Santiago
|
||||
drnic:
|
||||
id: 2
|
||||
name: Dr Nic
|
|
@ -1,34 +1,34 @@
|
|||
# From:
|
||||
# http://www.bigbold.com/snippets/posts/show/2178
|
||||
# http://blog.caboo.se/articles/2006/06/11/stupid-hash-tricks
|
||||
#
|
||||
# An example utilisation of these methods in a controller is:
|
||||
# def some_action
|
||||
# # some script kiddie also passed in :bee, which we don't want tampered with _here_.
|
||||
# @model = Model.create(params.pass(:foo, :bar))
|
||||
# end
|
||||
class Hash
|
||||
|
||||
# lets through the keys in the argument
|
||||
# >> {:one => 1, :two => 2, :three => 3}.pass(:one)
|
||||
# => {:one=>1}
|
||||
def pass(*keys)
|
||||
keys = keys.first if keys.first.is_a?(Array)
|
||||
tmp = self.clone
|
||||
tmp.delete_if {|k,v| ! keys.include?(k.to_sym) }
|
||||
tmp.delete_if {|k,v| ! keys.include?(k.to_s) }
|
||||
tmp
|
||||
end
|
||||
|
||||
# blocks the keys in the arguments
|
||||
# >> {:one => 1, :two => 2, :three => 3}.block(:one)
|
||||
# => {:two=>2, :three=>3}
|
||||
def block(*keys)
|
||||
keys = keys.first if keys.first.is_a?(Array)
|
||||
tmp = self.clone
|
||||
tmp.delete_if {|k,v| keys.include?(k.to_sym) }
|
||||
tmp.delete_if {|k,v| keys.include?(k.to_s) }
|
||||
tmp
|
||||
end
|
||||
|
||||
end
|
||||
# From:
|
||||
# http://www.bigbold.com/snippets/posts/show/2178
|
||||
# http://blog.caboo.se/articles/2006/06/11/stupid-hash-tricks
|
||||
#
|
||||
# An example utilisation of these methods in a controller is:
|
||||
# def some_action
|
||||
# # some script kiddie also passed in :bee, which we don't want tampered with _here_.
|
||||
# @model = Model.create(params.pass(:foo, :bar))
|
||||
# end
|
||||
class Hash
|
||||
|
||||
# lets through the keys in the argument
|
||||
# >> {:one => 1, :two => 2, :three => 3}.pass(:one)
|
||||
# => {:one=>1}
|
||||
def pass(*keys)
|
||||
keys = keys.first if keys.first.is_a?(Array)
|
||||
tmp = self.clone
|
||||
tmp.delete_if {|k,v| ! keys.include?(k.to_sym) }
|
||||
tmp.delete_if {|k,v| ! keys.include?(k.to_s) }
|
||||
tmp
|
||||
end
|
||||
|
||||
# blocks the keys in the arguments
|
||||
# >> {:one => 1, :two => 2, :three => 3}.block(:one)
|
||||
# => {:two=>2, :three=>3}
|
||||
def block(*keys)
|
||||
keys = keys.first if keys.first.is_a?(Array)
|
||||
tmp = self.clone
|
||||
tmp.delete_if {|k,v| keys.include?(k.to_sym) }
|
||||
tmp.delete_if {|k,v| keys.include?(k.to_s) }
|
||||
tmp
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,160 +1,160 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/article'
|
||||
require 'fixtures/product'
|
||||
require 'fixtures/tariff'
|
||||
require 'fixtures/product_tariff'
|
||||
require 'fixtures/suburb'
|
||||
require 'fixtures/street'
|
||||
require 'fixtures/restaurant'
|
||||
require 'fixtures/dorm'
|
||||
require 'fixtures/room'
|
||||
require 'fixtures/room_attribute'
|
||||
require 'fixtures/room_attribute_assignment'
|
||||
require 'fixtures/student'
|
||||
require 'fixtures/room_assignment'
|
||||
require 'fixtures/user'
|
||||
require 'fixtures/reading'
|
||||
|
||||
class TestAssociations < Test::Unit::TestCase
|
||||
fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
|
||||
:dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings
|
||||
|
||||
def test_has_many_through_with_conditions_when_through_association_is_not_composite
|
||||
user = User.find(:first)
|
||||
assert_equal 1, user.articles.find(:all, :conditions => ["articles.name = ?", "Article One"]).size
|
||||
end
|
||||
|
||||
def test_has_many_through_with_conditions_when_through_association_is_composite
|
||||
room = Room.find(:first)
|
||||
assert_equal 0, room.room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "keg"]).size
|
||||
end
|
||||
|
||||
def test_has_many_through_on_custom_finder_when_through_association_is_composite_finder_when_through_association_is_not_composite
|
||||
user = User.find(:first)
|
||||
assert_equal 1, user.find_custom_articles.size
|
||||
end
|
||||
|
||||
def test_has_many_through_on_custom_finder_when_through_association_is_composite
|
||||
room = Room.find(:first)
|
||||
assert_equal 0, room.find_custom_room_attributes.size
|
||||
end
|
||||
|
||||
def test_count
|
||||
assert_equal 2, Product.count(:include => :product_tariffs)
|
||||
assert_equal 3, Tariff.count(:include => :product_tariffs)
|
||||
assert_equal 2, Tariff.count(:group => :start_date).size
|
||||
end
|
||||
|
||||
def test_products
|
||||
assert_not_nil products(:first_product).product_tariffs
|
||||
assert_equal 2, products(:first_product).product_tariffs.length
|
||||
assert_not_nil products(:first_product).tariffs
|
||||
assert_equal 2, products(:first_product).tariffs.length
|
||||
assert_not_nil products(:first_product).product_tariff
|
||||
end
|
||||
|
||||
def test_product_tariffs
|
||||
assert_not_nil product_tariffs(:first_flat).product
|
||||
assert_not_nil product_tariffs(:first_flat).tariff
|
||||
assert_equal Product, product_tariffs(:first_flat).product.class
|
||||
assert_equal Tariff, product_tariffs(:first_flat).tariff.class
|
||||
end
|
||||
|
||||
def test_tariffs
|
||||
assert_not_nil tariffs(:flat).product_tariffs
|
||||
assert_equal 1, tariffs(:flat).product_tariffs.length
|
||||
assert_not_nil tariffs(:flat).products
|
||||
assert_equal 1, tariffs(:flat).products.length
|
||||
assert_not_nil tariffs(:flat).product_tariff
|
||||
end
|
||||
|
||||
# Its not generating the instances of associated classes from the rows
|
||||
def test_find_includes_products
|
||||
assert @products = Product.find(:all, :include => :product_tariffs)
|
||||
assert_equal 2, @products.length
|
||||
assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
||||
assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returned"
|
||||
end
|
||||
|
||||
def test_find_includes_tariffs
|
||||
assert @tariffs = Tariff.find(:all, :include => :product_tariffs)
|
||||
assert_equal 3, @tariffs.length
|
||||
assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
||||
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returnedturned"
|
||||
end
|
||||
|
||||
def test_find_includes_product
|
||||
assert @product_tariffs = ProductTariff.find(:all, :include => :product)
|
||||
assert_equal 3, @product_tariffs.length
|
||||
assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
|
||||
end
|
||||
|
||||
def test_find_includes_comp_belongs_to_tariff
|
||||
assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
|
||||
assert_equal 3, @product_tariffs.length
|
||||
assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
|
||||
end
|
||||
|
||||
def test_find_includes_extended
|
||||
assert @products = Product.find(:all, :include => {:product_tariffs => :tariff})
|
||||
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returned"
|
||||
|
||||
assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
|
||||
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returned"
|
||||
end
|
||||
|
||||
def test_join_where_clause
|
||||
@product = Product.find(:first, :include => :product_tariffs)
|
||||
where_clause = @product.product_tariffs.composite_where_clause(
|
||||
['foo','bar'], [1,2]
|
||||
)
|
||||
assert_equal('(foo=1 AND bar=2)', where_clause)
|
||||
end
|
||||
|
||||
def test_has_many_through
|
||||
@products = Product.find(:all, :include => :tariffs)
|
||||
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
|
||||
"Incorrect number of tariffs returned"
|
||||
end
|
||||
|
||||
def test_has_many_through_when_not_pre_loaded
|
||||
student = Student.find(:first)
|
||||
rooms = student.rooms
|
||||
assert_equal 1, rooms.size
|
||||
assert_equal 1, rooms.first.dorm_id
|
||||
assert_equal 1, rooms.first.room_id
|
||||
end
|
||||
|
||||
def test_has_many_through_when_through_association_is_composite
|
||||
dorm = Dorm.find(:first)
|
||||
assert_equal 1, dorm.rooms.length
|
||||
assert_equal 1, dorm.rooms.first.room_attributes.length
|
||||
assert_equal 'keg', dorm.rooms.first.room_attributes.first.name
|
||||
end
|
||||
|
||||
def test_associations_with_conditions
|
||||
@suburb = Suburb.find([2, 1])
|
||||
assert_equal 2, @suburb.streets.size
|
||||
|
||||
@suburb = Suburb.find([2, 1])
|
||||
assert_equal 1, @suburb.first_streets.size
|
||||
|
||||
@suburb = Suburb.find([2, 1], :include => :streets)
|
||||
assert_equal 2, @suburb.streets.size
|
||||
|
||||
@suburb = Suburb.find([2, 1], :include => :first_streets)
|
||||
assert_equal 1, @suburb.first_streets.size
|
||||
end
|
||||
|
||||
def test_has_and_belongs_to_many
|
||||
@restaurant = Restaurant.find([1,1])
|
||||
assert_equal 2, @restaurant.suburbs.size
|
||||
|
||||
@restaurant = Restaurant.find([1,1], :include => :suburbs)
|
||||
assert_equal 2, @restaurant.suburbs.size
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/article'
|
||||
require 'fixtures/product'
|
||||
require 'fixtures/tariff'
|
||||
require 'fixtures/product_tariff'
|
||||
require 'fixtures/suburb'
|
||||
require 'fixtures/street'
|
||||
require 'fixtures/restaurant'
|
||||
require 'fixtures/dorm'
|
||||
require 'fixtures/room'
|
||||
require 'fixtures/room_attribute'
|
||||
require 'fixtures/room_attribute_assignment'
|
||||
require 'fixtures/student'
|
||||
require 'fixtures/room_assignment'
|
||||
require 'fixtures/user'
|
||||
require 'fixtures/reading'
|
||||
|
||||
class TestAssociations < Test::Unit::TestCase
|
||||
fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
|
||||
:dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings
|
||||
|
||||
def test_has_many_through_with_conditions_when_through_association_is_not_composite
|
||||
user = User.find(:first)
|
||||
assert_equal 1, user.articles.find(:all, :conditions => ["articles.name = ?", "Article One"]).size
|
||||
end
|
||||
|
||||
def test_has_many_through_with_conditions_when_through_association_is_composite
|
||||
room = Room.find(:first)
|
||||
assert_equal 0, room.room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "keg"]).size
|
||||
end
|
||||
|
||||
def test_has_many_through_on_custom_finder_when_through_association_is_composite_finder_when_through_association_is_not_composite
|
||||
user = User.find(:first)
|
||||
assert_equal 1, user.find_custom_articles.size
|
||||
end
|
||||
|
||||
def test_has_many_through_on_custom_finder_when_through_association_is_composite
|
||||
room = Room.find(:first)
|
||||
assert_equal 0, room.find_custom_room_attributes.size
|
||||
end
|
||||
|
||||
def test_count
|
||||
assert_equal 2, Product.count(:include => :product_tariffs)
|
||||
assert_equal 3, Tariff.count(:include => :product_tariffs)
|
||||
assert_equal 2, Tariff.count(:group => :start_date).size
|
||||
end
|
||||
|
||||
def test_products
|
||||
assert_not_nil products(:first_product).product_tariffs
|
||||
assert_equal 2, products(:first_product).product_tariffs.length
|
||||
assert_not_nil products(:first_product).tariffs
|
||||
assert_equal 2, products(:first_product).tariffs.length
|
||||
assert_not_nil products(:first_product).product_tariff
|
||||
end
|
||||
|
||||
def test_product_tariffs
|
||||
assert_not_nil product_tariffs(:first_flat).product
|
||||
assert_not_nil product_tariffs(:first_flat).tariff
|
||||
assert_equal Product, product_tariffs(:first_flat).product.class
|
||||
assert_equal Tariff, product_tariffs(:first_flat).tariff.class
|
||||
end
|
||||
|
||||
def test_tariffs
|
||||
assert_not_nil tariffs(:flat).product_tariffs
|
||||
assert_equal 1, tariffs(:flat).product_tariffs.length
|
||||
assert_not_nil tariffs(:flat).products
|
||||
assert_equal 1, tariffs(:flat).products.length
|
||||
assert_not_nil tariffs(:flat).product_tariff
|
||||
end
|
||||
|
||||
# Its not generating the instances of associated classes from the rows
|
||||
def test_find_includes_products
|
||||
assert @products = Product.find(:all, :include => :product_tariffs)
|
||||
assert_equal 2, @products.length
|
||||
assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
||||
assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returned"
|
||||
end
|
||||
|
||||
def test_find_includes_tariffs
|
||||
assert @tariffs = Tariff.find(:all, :include => :product_tariffs)
|
||||
assert_equal 3, @tariffs.length
|
||||
assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
||||
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returnedturned"
|
||||
end
|
||||
|
||||
def test_find_includes_product
|
||||
assert @product_tariffs = ProductTariff.find(:all, :include => :product)
|
||||
assert_equal 3, @product_tariffs.length
|
||||
assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
|
||||
end
|
||||
|
||||
def test_find_includes_comp_belongs_to_tariff
|
||||
assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
|
||||
assert_equal 3, @product_tariffs.length
|
||||
assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
|
||||
end
|
||||
|
||||
def test_find_includes_extended
|
||||
assert @products = Product.find(:all, :include => {:product_tariffs => :tariff})
|
||||
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returned"
|
||||
|
||||
assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
|
||||
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
||||
"Incorrect number of product_tariffs returned"
|
||||
end
|
||||
|
||||
def test_join_where_clause
|
||||
@product = Product.find(:first, :include => :product_tariffs)
|
||||
where_clause = @product.product_tariffs.composite_where_clause(
|
||||
['foo','bar'], [1,2]
|
||||
)
|
||||
assert_equal('(foo=1 AND bar=2)', where_clause)
|
||||
end
|
||||
|
||||
def test_has_many_through
|
||||
@products = Product.find(:all, :include => :tariffs)
|
||||
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
|
||||
"Incorrect number of tariffs returned"
|
||||
end
|
||||
|
||||
def test_has_many_through_when_not_pre_loaded
|
||||
student = Student.find(:first)
|
||||
rooms = student.rooms
|
||||
assert_equal 1, rooms.size
|
||||
assert_equal 1, rooms.first.dorm_id
|
||||
assert_equal 1, rooms.first.room_id
|
||||
end
|
||||
|
||||
def test_has_many_through_when_through_association_is_composite
|
||||
dorm = Dorm.find(:first)
|
||||
assert_equal 1, dorm.rooms.length
|
||||
assert_equal 1, dorm.rooms.first.room_attributes.length
|
||||
assert_equal 'keg', dorm.rooms.first.room_attributes.first.name
|
||||
end
|
||||
|
||||
def test_associations_with_conditions
|
||||
@suburb = Suburb.find([2, 1])
|
||||
assert_equal 2, @suburb.streets.size
|
||||
|
||||
@suburb = Suburb.find([2, 1])
|
||||
assert_equal 1, @suburb.first_streets.size
|
||||
|
||||
@suburb = Suburb.find([2, 1], :include => :streets)
|
||||
assert_equal 2, @suburb.streets.size
|
||||
|
||||
@suburb = Suburb.find([2, 1], :include => :first_streets)
|
||||
assert_equal 1, @suburb.first_streets.size
|
||||
end
|
||||
|
||||
def test_has_and_belongs_to_many
|
||||
@restaurant = Restaurant.find([1,1])
|
||||
assert_equal 2, @restaurant.suburbs.size
|
||||
|
||||
@restaurant = Restaurant.find([1,1], :include => :suburbs)
|
||||
assert_equal 2, @restaurant.suburbs.size
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestClone < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_truth
|
||||
testing_with do
|
||||
clone = @first.clone
|
||||
assert_equal @first.attributes.block(@klass.primary_key), clone.attributes
|
||||
if composite?
|
||||
@klass.primary_key.each {|key| assert_nil clone[key], "Primary key '#{key}' should be nil"}
|
||||
else
|
||||
assert_nil clone[@klass.primary_key], "Sole primary key should be nil"
|
||||
end
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestClone < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_truth
|
||||
testing_with do
|
||||
clone = @first.clone
|
||||
assert_equal @first.attributes.block(@klass.primary_key), clone.attributes
|
||||
if composite?
|
||||
@klass.primary_key.each {|key| assert_nil clone[key], "Primary key '#{key}' should be nil"}
|
||||
else
|
||||
assert_nil clone[@klass.primary_key], "Sole primary key should be nil"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,96 +1,96 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
require 'fixtures/department'
|
||||
require 'fixtures/employee'
|
||||
|
||||
class TestDelete < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes, :departments, :employees
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_destroy_one
|
||||
testing_with do
|
||||
#assert @first.destroy
|
||||
assert true
|
||||
end
|
||||
end
|
||||
|
||||
def test_destroy_one_via_class
|
||||
testing_with do
|
||||
assert @klass.destroy(*@first.id)
|
||||
end
|
||||
end
|
||||
|
||||
def test_destroy_one_alone_via_class
|
||||
testing_with do
|
||||
assert @klass.destroy(@first.id)
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_one
|
||||
testing_with do
|
||||
assert @klass.delete(*@first.id) if composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_one_alone
|
||||
testing_with do
|
||||
assert @klass.delete(@first.id)
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_many
|
||||
testing_with do
|
||||
to_delete = @klass.find(:all)[0..1]
|
||||
assert_equal 2, to_delete.length
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_all
|
||||
testing_with do
|
||||
@klass.delete_all
|
||||
end
|
||||
end
|
||||
|
||||
def test_clear_association
|
||||
department = Department.find(1,1)
|
||||
assert_equal 2, department.employees.size, "Before clear employee count should be 2."
|
||||
department.employees.clear
|
||||
assert_equal 0, department.employees.size, "After clear employee count should be 0."
|
||||
department.reload
|
||||
assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
|
||||
end
|
||||
|
||||
def test_delete_association
|
||||
department = Department.find(1,1)
|
||||
assert_equal 2, department.employees.size , "Before delete employee count should be 2."
|
||||
first_employee = department.employees[0]
|
||||
department.employees.delete(first_employee)
|
||||
assert_equal 1, department.employees.size, "After delete employee count should be 1."
|
||||
department.reload
|
||||
assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
|
||||
end
|
||||
|
||||
def test_delete_records_for_has_many_association_with_composite_primary_key
|
||||
reference_type = ReferenceType.find(1)
|
||||
codes_to_delete = reference_type.reference_codes[0..1]
|
||||
assert_equal 3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3."
|
||||
reference_type.reference_codes.delete_records(codes_to_delete)
|
||||
reference_type.reload
|
||||
assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
require 'fixtures/department'
|
||||
require 'fixtures/employee'
|
||||
|
||||
class TestDelete < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes, :departments, :employees
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_destroy_one
|
||||
testing_with do
|
||||
#assert @first.destroy
|
||||
assert true
|
||||
end
|
||||
end
|
||||
|
||||
def test_destroy_one_via_class
|
||||
testing_with do
|
||||
assert @klass.destroy(*@first.id)
|
||||
end
|
||||
end
|
||||
|
||||
def test_destroy_one_alone_via_class
|
||||
testing_with do
|
||||
assert @klass.destroy(@first.id)
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_one
|
||||
testing_with do
|
||||
assert @klass.delete(*@first.id) if composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_one_alone
|
||||
testing_with do
|
||||
assert @klass.delete(@first.id)
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_many
|
||||
testing_with do
|
||||
to_delete = @klass.find(:all)[0..1]
|
||||
assert_equal 2, to_delete.length
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_all
|
||||
testing_with do
|
||||
@klass.delete_all
|
||||
end
|
||||
end
|
||||
|
||||
def test_clear_association
|
||||
department = Department.find(1,1)
|
||||
assert_equal 2, department.employees.size, "Before clear employee count should be 2."
|
||||
department.employees.clear
|
||||
assert_equal 0, department.employees.size, "After clear employee count should be 0."
|
||||
department.reload
|
||||
assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
|
||||
end
|
||||
|
||||
def test_delete_association
|
||||
department = Department.find(1,1)
|
||||
assert_equal 2, department.employees.size , "Before delete employee count should be 2."
|
||||
first_employee = department.employees[0]
|
||||
department.employees.delete(first_employee)
|
||||
assert_equal 1, department.employees.size, "After delete employee count should be 1."
|
||||
department.reload
|
||||
assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
|
||||
end
|
||||
|
||||
def test_delete_records_for_has_many_association_with_composite_primary_key
|
||||
reference_type = ReferenceType.find(1)
|
||||
codes_to_delete = reference_type.reference_codes[0..1]
|
||||
assert_equal 3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3."
|
||||
reference_type.reference_codes.delete_records(codes_to_delete)
|
||||
reference_type.reload
|
||||
assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestDummy < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
classes = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = classes
|
||||
end
|
||||
|
||||
def test_truth
|
||||
testing_with do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestDummy < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
classes = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = classes
|
||||
end
|
||||
|
||||
def test_truth
|
||||
testing_with do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,73 +1,73 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
# Testing the find action on composite ActiveRecords with two primary keys
|
||||
class TestFind < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => [:reference_type_id],
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
:dual_strs => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => ['reference_type_id', 'reference_code'],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_find_first
|
||||
testing_with do
|
||||
obj = @klass.find(:first)
|
||||
assert obj
|
||||
assert_equal @klass, obj.class
|
||||
end
|
||||
end
|
||||
|
||||
def test_find
|
||||
testing_with do
|
||||
found = @klass.find(*first_id) # e.g. find(1,1) or find 1,1
|
||||
assert found
|
||||
assert_equal @klass, found.class
|
||||
assert_equal found, @klass.find(found.id)
|
||||
assert_equal found, @klass.find(found.to_param)
|
||||
end
|
||||
end
|
||||
|
||||
def test_find_composite_ids
|
||||
testing_with do
|
||||
found = @klass.find(first_id) # e.g. find([1,1].to_composite_ids)
|
||||
assert found
|
||||
assert_equal @klass, found.class
|
||||
assert_equal found, @klass.find(found.id)
|
||||
assert_equal found, @klass.find(found.to_param)
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_param
|
||||
testing_with do
|
||||
assert_equal first_id_str, @first.to_param.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def things_to_look_at
|
||||
testing_with do
|
||||
assert_equal found, @klass.find(found.id.to_s) # fails for 2+ keys
|
||||
end
|
||||
end
|
||||
|
||||
def test_not_found
|
||||
assert_raise(::ActiveRecord::RecordNotFound) do
|
||||
ReferenceCode.send :find, '999,999'
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
# Testing the find action on composite ActiveRecords with two primary keys
|
||||
class TestFind < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => [:reference_type_id],
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
:dual_strs => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => ['reference_type_id', 'reference_code'],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_find_first
|
||||
testing_with do
|
||||
obj = @klass.find(:first)
|
||||
assert obj
|
||||
assert_equal @klass, obj.class
|
||||
end
|
||||
end
|
||||
|
||||
def test_find
|
||||
testing_with do
|
||||
found = @klass.find(*first_id) # e.g. find(1,1) or find 1,1
|
||||
assert found
|
||||
assert_equal @klass, found.class
|
||||
assert_equal found, @klass.find(found.id)
|
||||
assert_equal found, @klass.find(found.to_param)
|
||||
end
|
||||
end
|
||||
|
||||
def test_find_composite_ids
|
||||
testing_with do
|
||||
found = @klass.find(first_id) # e.g. find([1,1].to_composite_ids)
|
||||
assert found
|
||||
assert_equal @klass, found.class
|
||||
assert_equal found, @klass.find(found.id)
|
||||
assert_equal found, @klass.find(found.to_param)
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_param
|
||||
testing_with do
|
||||
assert_equal first_id_str, @first.to_param.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def things_to_look_at
|
||||
testing_with do
|
||||
assert_equal found, @klass.find(found.id.to_s) # fails for 2+ keys
|
||||
end
|
||||
end
|
||||
|
||||
def test_not_found
|
||||
assert_raise(::ActiveRecord::RecordNotFound) do
|
||||
ReferenceCode.send :find, '999,999'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,97 +1,97 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestIds < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => [:reference_type_id],
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
:dual_strs => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => ['reference_type_id', 'reference_code'],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_id
|
||||
testing_with do
|
||||
assert_equal @first.id, @first.ids if composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_id_to_s
|
||||
testing_with do
|
||||
assert_equal first_id_str, @first.id.to_s
|
||||
assert_equal first_id_str, "#{@first.id}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_ids_to_s
|
||||
testing_with do
|
||||
order = @klass.primary_key.is_a?(String) ? @klass.primary_key : @klass.primary_key.join(',')
|
||||
to_test = @klass.find(:all, :order => order)[0..1].map(&:id)
|
||||
assert_equal '(1,1),(1,2)', @klass.ids_to_s(to_test) if @key_test == :dual
|
||||
assert_equal '1,1;1,2', @klass.ids_to_s(to_test, ',', ';', '', '') if @key_test == :dual
|
||||
end
|
||||
end
|
||||
|
||||
def test_composite_where_clause
|
||||
testing_with do
|
||||
where = 'reference_codes.reference_type_id=1 AND reference_codes.reference_code=2) OR (reference_codes.reference_type_id=2 AND reference_codes.reference_code=2'
|
||||
assert_equal(where, @klass.composite_where_clause([[1, 2], [2, 2]])) if @key_test == :dual
|
||||
end
|
||||
end
|
||||
|
||||
def test_set_ids_string
|
||||
testing_with do
|
||||
array = @primary_keys.collect {|key| 5}
|
||||
expected = composite? ? array.to_composite_keys : array.first
|
||||
@first.id = expected.to_s
|
||||
assert_equal expected, @first.id
|
||||
end
|
||||
end
|
||||
|
||||
def test_set_ids_array
|
||||
testing_with do
|
||||
array = @primary_keys.collect {|key| 5}
|
||||
expected = composite? ? array.to_composite_keys : array.first
|
||||
@first.id = expected
|
||||
assert_equal expected, @first.id
|
||||
end
|
||||
end
|
||||
|
||||
def test_set_ids_comp
|
||||
testing_with do
|
||||
array = @primary_keys.collect {|key| 5}
|
||||
expected = composite? ? array.to_composite_keys : array.first
|
||||
@first.id = expected
|
||||
assert_equal expected, @first.id
|
||||
end
|
||||
end
|
||||
|
||||
def test_primary_keys
|
||||
testing_with do
|
||||
if composite?
|
||||
assert_not_nil @klass.primary_keys
|
||||
assert_equal @primary_keys.map {|key| key.to_sym}, @klass.primary_keys
|
||||
assert_equal @klass.primary_keys, @klass.primary_key
|
||||
else
|
||||
assert_not_nil @klass.primary_key
|
||||
assert_equal @primary_keys, [@klass.primary_key.to_sym]
|
||||
end
|
||||
assert_equal @primary_keys.join(','), @klass.primary_key.to_s
|
||||
# Need a :primary_keys should be Array with to_s overridden
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestIds < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => [:reference_type_id],
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
:dual_strs => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => ['reference_type_id', 'reference_code'],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_id
|
||||
testing_with do
|
||||
assert_equal @first.id, @first.ids if composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_id_to_s
|
||||
testing_with do
|
||||
assert_equal first_id_str, @first.id.to_s
|
||||
assert_equal first_id_str, "#{@first.id}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_ids_to_s
|
||||
testing_with do
|
||||
order = @klass.primary_key.is_a?(String) ? @klass.primary_key : @klass.primary_key.join(',')
|
||||
to_test = @klass.find(:all, :order => order)[0..1].map(&:id)
|
||||
assert_equal '(1,1),(1,2)', @klass.ids_to_s(to_test) if @key_test == :dual
|
||||
assert_equal '1,1;1,2', @klass.ids_to_s(to_test, ',', ';', '', '') if @key_test == :dual
|
||||
end
|
||||
end
|
||||
|
||||
def test_composite_where_clause
|
||||
testing_with do
|
||||
where = 'reference_codes.reference_type_id=1 AND reference_codes.reference_code=2) OR (reference_codes.reference_type_id=2 AND reference_codes.reference_code=2'
|
||||
assert_equal(where, @klass.composite_where_clause([[1, 2], [2, 2]])) if @key_test == :dual
|
||||
end
|
||||
end
|
||||
|
||||
def test_set_ids_string
|
||||
testing_with do
|
||||
array = @primary_keys.collect {|key| 5}
|
||||
expected = composite? ? array.to_composite_keys : array.first
|
||||
@first.id = expected.to_s
|
||||
assert_equal expected, @first.id
|
||||
end
|
||||
end
|
||||
|
||||
def test_set_ids_array
|
||||
testing_with do
|
||||
array = @primary_keys.collect {|key| 5}
|
||||
expected = composite? ? array.to_composite_keys : array.first
|
||||
@first.id = expected
|
||||
assert_equal expected, @first.id
|
||||
end
|
||||
end
|
||||
|
||||
def test_set_ids_comp
|
||||
testing_with do
|
||||
array = @primary_keys.collect {|key| 5}
|
||||
expected = composite? ? array.to_composite_keys : array.first
|
||||
@first.id = expected
|
||||
assert_equal expected, @first.id
|
||||
end
|
||||
end
|
||||
|
||||
def test_primary_keys
|
||||
testing_with do
|
||||
if composite?
|
||||
assert_not_nil @klass.primary_keys
|
||||
assert_equal @primary_keys.map {|key| key.to_sym}, @klass.primary_keys
|
||||
assert_equal @klass.primary_keys, @klass.primary_key
|
||||
else
|
||||
assert_not_nil @klass.primary_key
|
||||
assert_equal @primary_keys, [@klass.primary_key.to_sym]
|
||||
end
|
||||
assert_equal @primary_keys.join(','), @klass.primary_key.to_s
|
||||
# Need a :primary_keys should be Array with to_s overridden
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,39 +1,39 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestMiscellaneous < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes, :products
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_composite_class
|
||||
testing_with do
|
||||
assert_equal composite?, @klass.composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_composite_instance
|
||||
testing_with do
|
||||
assert_equal composite?, @first.composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_count
|
||||
assert_equal 2, Product.count
|
||||
end
|
||||
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestMiscellaneous < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes, :products
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_composite_class
|
||||
testing_with do
|
||||
assert_equal composite?, @klass.composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_composite_instance
|
||||
testing_with do
|
||||
assert_equal composite?, @first.composite?
|
||||
end
|
||||
end
|
||||
|
||||
def test_count
|
||||
assert_equal 2, Product.count
|
||||
end
|
||||
|
||||
end
|
|
@ -1,38 +1,38 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
require 'plugins/pagination'
|
||||
|
||||
class TestPagination < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
include ActionController::Pagination
|
||||
DEFAULT_PAGE_SIZE = 2
|
||||
|
||||
attr_accessor :params
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
:table => :reference_types,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
:table => :reference_codes,
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
@params = {}
|
||||
end
|
||||
|
||||
def test_paginate_all
|
||||
testing_with do
|
||||
@object_pages, @objects = paginate @klass_info[:table], :per_page => DEFAULT_PAGE_SIZE
|
||||
assert_equal 2, @objects.length, "Each page should have #{DEFAULT_PAGE_SIZE} items"
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
require 'plugins/pagination'
|
||||
|
||||
class TestPagination < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
include ActionController::Pagination
|
||||
DEFAULT_PAGE_SIZE = 2
|
||||
|
||||
attr_accessor :params
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
:table => :reference_types,
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
:table => :reference_codes,
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
@params = {}
|
||||
end
|
||||
|
||||
def test_paginate_all
|
||||
testing_with do
|
||||
@object_pages, @objects = paginate @klass_info[:table], :per_page => DEFAULT_PAGE_SIZE
|
||||
assert_equal 2, @objects.length, "Each page should have #{DEFAULT_PAGE_SIZE} items"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,27 +1,27 @@
|
|||
# Test cases devised by Santiago that broke the Composite Primary Keys
|
||||
# code at one point in time. But no more!!!
|
||||
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/user'
|
||||
require 'fixtures/article'
|
||||
require 'fixtures/reading'
|
||||
|
||||
class TestSantiago < Test::Unit::TestCase
|
||||
fixtures :suburbs, :streets, :users, :articles, :readings
|
||||
|
||||
def test_normal_and_composite_associations
|
||||
assert_not_nil @suburb = Suburb.find(1,1)
|
||||
assert_equal 1, @suburb.streets.length
|
||||
|
||||
assert_not_nil @street = Street.find(1)
|
||||
assert_not_nil @street.suburb
|
||||
end
|
||||
|
||||
def test_single_keys
|
||||
@santiago = User.find(1)
|
||||
assert_not_nil @santiago.articles
|
||||
assert_equal 2, @santiago.articles.length
|
||||
assert_not_nil @santiago.readings
|
||||
assert_equal 2, @santiago.readings.length
|
||||
end
|
||||
end
|
||||
# Test cases devised by Santiago that broke the Composite Primary Keys
|
||||
# code at one point in time. But no more!!!
|
||||
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/user'
|
||||
require 'fixtures/article'
|
||||
require 'fixtures/reading'
|
||||
|
||||
class TestSantiago < Test::Unit::TestCase
|
||||
fixtures :suburbs, :streets, :users, :articles, :readings
|
||||
|
||||
def test_normal_and_composite_associations
|
||||
assert_not_nil @suburb = Suburb.find(1,1)
|
||||
assert_equal 1, @suburb.streets.length
|
||||
|
||||
assert_not_nil @street = Street.find(1)
|
||||
assert_not_nil @street.suburb
|
||||
end
|
||||
|
||||
def test_single_keys
|
||||
@santiago = User.find(1)
|
||||
assert_not_nil @santiago.articles
|
||||
assert_equal 2, @santiago.articles.length
|
||||
assert_not_nil @santiago.readings
|
||||
assert_equal 2, @santiago.readings.length
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestUpdate < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
:update => { :description => 'RT Desc' },
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
:update => { :description => 'RT Desc' },
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_setup
|
||||
testing_with do
|
||||
assert_not_nil @klass_info[:update]
|
||||
end
|
||||
end
|
||||
|
||||
def test_update_attributes
|
||||
testing_with do
|
||||
assert @first.update_attributes(@klass_info[:update])
|
||||
assert @first.reload
|
||||
@klass_info[:update].each_pair do |attr_name, new_value|
|
||||
assert_equal new_value, @first[attr_name], "Attribute #{attr_name} is incorrect"
|
||||
end
|
||||
end
|
||||
end
|
||||
require 'abstract_unit'
|
||||
require 'fixtures/reference_type'
|
||||
require 'fixtures/reference_code'
|
||||
|
||||
class TestUpdate < Test::Unit::TestCase
|
||||
fixtures :reference_types, :reference_codes
|
||||
|
||||
CLASSES = {
|
||||
:single => {
|
||||
:class => ReferenceType,
|
||||
:primary_keys => :reference_type_id,
|
||||
:update => { :description => 'RT Desc' },
|
||||
},
|
||||
:dual => {
|
||||
:class => ReferenceCode,
|
||||
:primary_keys => [:reference_type_id, :reference_code],
|
||||
:update => { :description => 'RT Desc' },
|
||||
},
|
||||
}
|
||||
|
||||
def setup
|
||||
self.class.classes = CLASSES
|
||||
end
|
||||
|
||||
def test_setup
|
||||
testing_with do
|
||||
assert_not_nil @klass_info[:update]
|
||||
end
|
||||
end
|
||||
|
||||
def test_update_attributes
|
||||
testing_with do
|
||||
assert @first.update_attributes(@klass_info[:update])
|
||||
assert @first.reload
|
||||
@klass_info[:update].each_pair do |attr_name, new_value|
|
||||
assert_equal new_value, @first[attr_name], "Attribute #{attr_name} is incorrect"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue