From 57a29efea95e57734df9efc14ea929d64e0bcfd6 Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Wed, 7 May 2008 09:28:03 +0200 Subject: [PATCH] Model refactorings and further expansion of specs * Changed associations (except for many_to_many) to use new shorthand syntax, for sake of clarity. * Changed "validate" reference to "dm-validations" to reflect gem renaming in dm-more. * Added basic specs for most associations. * Updated some :class_name options for associations (still needs to be gone through and tested more thoroughly). * Added missing class and instance methods in Mart::AbstractUpload, Mart::Accounts * Added zipcode, province aliases in Address class (and relevant specs) * Added provinces alias in Country class (and relevant specs). * Added validations into Country class, made name property unique. * Add spec for State class. * Pushed down image-related properties/constants, out of AbstractUpload and into Mart::Image class. * Add example workaround for current lack of DM many-to-many support in Right class. * Fixed finder ordering syntax in Tag. * Re-enabled :save callback in User class. * Made some Mart::Order specs pending, instead of letting them fail. --- app/models/address.rb | 17 ++++--- app/models/country.rb | 9 +++- app/models/mart/abstract_upload.rb | 17 +++++-- app/models/mart/accounts/abstract_account.rb | 19 +++++-- app/models/mart/customer.rb | 27 ++++------ app/models/mart/customers/wishlist_item.rb | 8 +-- app/models/mart/image.rb | 9 +++- app/models/mart/order.rb | 19 ++++--- app/models/mart/orders/line_item.rb | 4 +- app/models/mart/orders/status_code.rb | 2 +- app/models/mart/shipping/type.rb | 4 +- app/models/mart/shipping/weight.rb | 2 +- app/models/mart/store/abstract_item.rb | 12 ++--- app/models/mart/store/product.rb | 6 +-- app/models/mart/store/product_image.rb | 4 +- app/models/mart/store/promotion.rb | 6 +-- app/models/mart/store/variation.rb | 2 +- app/models/right.rb | 15 +++++- app/models/state.rb | 2 +- app/models/tag.rb | 18 +++---- app/models/user.rb | 12 ++--- spec/models/address_spec.rb | 54 +++++++++++++++----- spec/models/country_spec.rb | 22 ++++++++ spec/models/mart/asset_spec.rb | 21 ++------ spec/models/mart/customer_spec.rb | 33 +++++++++--- spec/models/mart/customers/wishlist_item_spec.rb | 6 +-- spec/models/mart/image_spec.rb | 10 ++-- spec/models/mart/order_spec.rb | 64 +++++++++++++++++------- spec/models/mart/orders/line_item_spec.rb | 14 ++++-- spec/models/mart/orders/status_code_spec.rb | 9 ++-- spec/models/mart/shipping/weight_spec.rb | 5 +- spec/models/mart/store/abstract_item_spec.rb | 5 -- spec/models/mart/store/product_image_spec.rb | 11 +++- spec/models/mart/store/product_spec.rb | 28 +++++++++-- spec/models/mart/store/promotion_spec.rb | 10 +++- spec/models/mart/store/variation_spec.rb | 10 +++- spec/models/right_spec.rb | 6 ++- spec/models/role_spec.rb | 18 +++++-- spec/models/state_spec.rb | 13 +++++ spec/models/tag_spec.rb | 18 +++---- 40 files changed, 389 insertions(+), 182 deletions(-) create mode 100644 spec/models/state_spec.rb diff --git a/app/models/address.rb b/app/models/address.rb index 4956568..e5335bf 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -1,5 +1,3 @@ -require 'validate' - class Address include DataMapper::Resource @@ -16,17 +14,22 @@ class Address property :state_id, Fixnum # foreign-key property :country_code, String # foreign-key - many_to_one :state - many_to_one :country + belongs_to :state + belongs_to :country validates_presence_of :first_name validates_presence_of :last_name - validates_presence_of :address - validates_presence_of :zip + validates_presence_of :address1 + validates_presence_of :postal_code validates_length_of :first_name, :maximum => 50 validates_length_of :last_name, :maximum => 50 - validates_length_of :address, :maximum => 255 + validates_length_of :address1, :maximum => 255 + + alias :zipcode :postal_code + alias :zipcode= :postal_code= + alias :province :state + alias :province= :state= def name "#{self.first_name} #{self.last_name}" diff --git a/app/models/country.rb b/app/models/country.rb index acd6e60..537abb3 100644 --- a/app/models/country.rb +++ b/app/models/country.rb @@ -8,6 +8,13 @@ class Country include DataMapper::Validate property :code, String, :serial => true, :length => 2 # ISO 3166-1 alpha-2 - property :name, String, :length => 100, :nullable => false + property :name, String, :length => 100, :nullable => false, :unique => true + + has n, :states + + validates_presence_of :name + validates_uniqueness_of :name + + alias :provinces :states end \ No newline at end of file diff --git a/app/models/mart/abstract_upload.rb b/app/models/mart/abstract_upload.rb index 6885293..613a8c2 100644 --- a/app/models/mart/abstract_upload.rb +++ b/app/models/mart/abstract_upload.rb @@ -2,13 +2,10 @@ module Mart class AbstractUpload include DataMapper::Resource - - IMAGE_EXTENSIONS = ['gif', 'jpg', 'jpeg', 'png', 'bmp'] + include DataMapper::Validate property :id, Fixnum, :serial => true property :filename, String - property :width, Fixnum, :default => 0, :nullable => false - property :height, Fixnum, :default => 0, :nullable => false property :created_on, DateTime #property :parent_id property :content_type, String @@ -16,5 +13,17 @@ module Mart property :size, Fixnum property :type, Class # single-table inheritance + def filename_base + filename.split('.').first + end + + def extension + filename.split('.').last + end + + def relative_path + filename # TODO + end + end end diff --git a/app/models/mart/accounts/abstract_account.rb b/app/models/mart/accounts/abstract_account.rb index 9bbb726..805fd99 100644 --- a/app/models/mart/accounts/abstract_account.rb +++ b/app/models/mart/accounts/abstract_account.rb @@ -1,4 +1,4 @@ -require 'validate' +require 'dm-validations' module Mart module Accounts @@ -12,8 +12,21 @@ module Mart property :order_id, Fixnum # foreign-key property :customer_id, Fixnum # foreign-key - one_to_one :order - many_to_one :customer #, :accessor => :protected + has 1, :order + belongs_to :customer #, :accessor => :protected + + def self.months + (1..12).to_a + end + + def self.years + year = Date.today.year + years = Array.new + (0..9).each do |n| + years << year + n + end + years + end end end diff --git a/app/models/mart/customer.rb b/app/models/mart/customer.rb index 75b781c..b18c828 100644 --- a/app/models/mart/customer.rb +++ b/app/models/mart/customer.rb @@ -1,4 +1,4 @@ -require 'validate' +require 'dm-validations' module Mart class Customer @@ -14,23 +14,18 @@ module Mart property :first_name, String, :length => 50, :nullable => false property :last_name, String, :length => 50, :nullable => false - one_to_many :orders #, - #:dependent => :nullify, - #:order => "created_on DESC" - one_to_many :last_order#, - #:class_name => "Order", - #:order => "created_on DESC" - one_to_many :order_addresses #, :dependent => :destroy - one_to_many :order_accounts #, :dependent => :destroy - - one_to_many :wishlist_items #, - #:dependent => :destroy, - #:order => "created_on DESC" - one_to_many :items #, :through => :wishlist_items, - #:order => "wishlist_items.created_on DESC" + has n, :orders + has n, :addresses + has n, :accounts + has n, :wishlist_items + # has n, :items, :through => :wishlist_items ## FIXME validates_presence_of :email_address - #validates_length_of :email_address, :maximum => 255 + validates_length_of :email_address, :maximum => 255 + + def last_order + # TODO + end end end \ No newline at end of file diff --git a/app/models/mart/customers/wishlist_item.rb b/app/models/mart/customers/wishlist_item.rb index 521d36f..d85f7c4 100644 --- a/app/models/mart/customers/wishlist_item.rb +++ b/app/models/mart/customers/wishlist_item.rb @@ -9,10 +9,10 @@ module Mart property :created_on, DateTime property :customer_id, Fixnum # foreign-key property :store_item_id, Fixnum # foreign-key - - many_to_one :customer - many_to_one :store_item - + + belongs_to :customer + belongs_to :store_item + end end end \ No newline at end of file diff --git a/app/models/mart/image.rb b/app/models/mart/image.rb index c608ba1..a5ff983 100644 --- a/app/models/mart/image.rb +++ b/app/models/mart/image.rb @@ -1,8 +1,13 @@ module Mart class Image < AbstractUpload - one_to_many :product_images - one_to_many :products #, :through => :product_images + IMAGE_EXTENSIONS = ['gif', 'jpg', 'jpeg', 'png', 'bmp'] + + property :width, Fixnum, :default => 0, :nullable => false + property :height, Fixnum, :default => 0, :nullable => false + + has n, :product_images + #has n, :products, :through => :product_images ## FIXME end end \ No newline at end of file diff --git a/app/models/mart/order.rb b/app/models/mart/order.rb index 8738ea5..41f9fd8 100644 --- a/app/models/mart/order.rb +++ b/app/models/mart/order.rb @@ -1,4 +1,4 @@ -require 'validate' +require 'dm-validations' module Mart class Order @@ -23,16 +23,15 @@ module Mart property :status_code_id,Fixnum # foreign-key property :promotion_id, Fixnum # foreign-key - one_to_many :line_items, :class_name => 'Orders::LineItem' #, :dependent => :destroy + has 1..n, :line_items, :class_name => 'Orders::LineItem' #, :dependent => :destroy + has 1, :billing_address, :class_name => 'Address' #, :foreign_key => 'billing_address_id' + has 1, :shipping_address, :class_name => 'Address' #, :foreign_key => 'shipping_address_id' - one_to_one :billing_address, :class_name => 'Address' #, :foreign_key => 'billing_address_id' - one_to_one :shipping_address, :class_name => 'Address' #, :foreign_key => 'shipping_address_id' - - many_to_one :account - many_to_one :customer - many_to_one :order_shipping_type - many_to_one :status_code, :class_name => 'Orders::StatusCode' - many_to_one :promotion + belongs_to :account + belongs_to :customer + belongs_to :order_shipping_type + belongs_to :status_code, :class_name => 'Orders::StatusCode' + belongs_to :promotion attr_accessor :promotion_code diff --git a/app/models/mart/orders/line_item.rb b/app/models/mart/orders/line_item.rb index 213ecb5..c4cfdaf 100644 --- a/app/models/mart/orders/line_item.rb +++ b/app/models/mart/orders/line_item.rb @@ -11,8 +11,8 @@ module Mart property :product_id, Fixnum ## FIXME: should not be both product_id + store_item_id property :store_item_id, Fixnum # foreign-key - many_to_one :product ## FIXME: should not be both product_id + store_item_id - many_to_one :store_item + belongs_to :product ## FIXME: should not be both product_id + store_item_id + belongs_to :store_item end end diff --git a/app/models/mart/orders/status_code.rb b/app/models/mart/orders/status_code.rb index 1568571..70a59d8 100644 --- a/app/models/mart/orders/status_code.rb +++ b/app/models/mart/orders/status_code.rb @@ -7,7 +7,7 @@ module Mart property :id, Fixnum, :serial => true property :name, String, :length => 30, :nullable => false - one_to_many :orders + has n, :orders end end diff --git a/app/models/mart/shipping/type.rb b/app/models/mart/shipping/type.rb index 0ab6b02..847938b 100644 --- a/app/models/mart/shipping/type.rb +++ b/app/models/mart/shipping/type.rb @@ -12,8 +12,8 @@ module Mart property :is_domestic, TrueClass, :default => true, :nullable => false property :price, Float, :default => 0.0, :nullable => false - one_to_many :orders - one_to_many :weights, :class_name => 'OrderShippingWeight' #, :dependent => :destroy + has n, :orders + has n, :weights, :class_name => 'OrderShippingWeight' #, :dependent => :destroy def self.get_domestic all(:is_domestic => true, :order => "price ASC") diff --git a/app/models/mart/shipping/weight.rb b/app/models/mart/shipping/weight.rb index 868e66f..3e7b309 100644 --- a/app/models/mart/shipping/weight.rb +++ b/app/models/mart/shipping/weight.rb @@ -10,7 +10,7 @@ module Mart property :price, Float, :default => 0.0, :nullable => false property :order_shipping_type_id, Fixnum # foreign-key - many_to_one :order_shipping_type + belongs_to :type end end diff --git a/app/models/mart/store/abstract_item.rb b/app/models/mart/store/abstract_item.rb index c56662f..b4fb3a6 100644 --- a/app/models/mart/store/abstract_item.rb +++ b/app/models/mart/store/abstract_item.rb @@ -1,5 +1,5 @@ require "date" -require "validate" +require "dm-validations" module Mart module Store @@ -21,12 +21,12 @@ module Mart property :weight, Float, :default => 0.0, :nullable => false property :is_discontinued, TrueClass, :default => false, :nullable => false property :type, Class # single-table inheritance - - one_to_many :order_line_items - one_to_many :wishlist_items #, :dependent => :destroy - + + has n, :line_items, :class_name => "Mart::Orders::LineItem" + has n, :wishlist_items, :class_name => "Mart::Customers::WishlistItem" #, :dependent => :destroy + validates_presence_of :name, :code - + end end end \ No newline at end of file diff --git a/app/models/mart/store/product.rb b/app/models/mart/store/product.rb index a240d70..d9c65b7 100644 --- a/app/models/mart/store/product.rb +++ b/app/models/mart/store/product.rb @@ -2,9 +2,9 @@ module Mart module Store class Product < AbstractItem - one_to_many :product_images - one_to_many :variations #, :dependent => :destroy, :order => 'name ASC' - one_to_many :images #, + has n, :product_images + has n, :variations #, :dependent => :destroy, :order => 'name ASC' + #has n, :images #, ## FIXME #:through => :product_images, #:order => "-product_images.rank DESC", #:dependent => :destroy diff --git a/app/models/mart/store/product_image.rb b/app/models/mart/store/product_image.rb index a64cd43..ea33269 100644 --- a/app/models/mart/store/product_image.rb +++ b/app/models/mart/store/product_image.rb @@ -8,8 +8,8 @@ module Mart property :image_id, Fixnum # foreign-key property :rank, Fixnum - many_to_one :product - many_to_one :image + belongs_to :product + belongs_to :image end end diff --git a/app/models/mart/store/promotion.rb b/app/models/mart/store/promotion.rb index 97ec999..668ec21 100644 --- a/app/models/mart/store/promotion.rb +++ b/app/models/mart/store/promotion.rb @@ -1,4 +1,4 @@ -require 'validate' +require 'dm-validations' module Mart module Store @@ -23,8 +23,8 @@ module Mart property :description, String, :nullable => false property :store_item_id, Fixnum # foreign-key - one_to_many :orders - many_to_one :store_item_id + has n, :orders + belongs_to :item, :class_name => "Mart::Store::AbstractItem" validates_presence_of :code, :discount_amount, :discount_type, :description validates_numericalnes_of :discount_amount diff --git a/app/models/mart/store/variation.rb b/app/models/mart/store/variation.rb index c876b93..95856bd 100644 --- a/app/models/mart/store/variation.rb +++ b/app/models/mart/store/variation.rb @@ -4,7 +4,7 @@ module Mart property :product_id, Fixnum # foreign-key - many_to_one :product + belongs_to :product end end diff --git a/app/models/right.rb b/app/models/right.rb index a755572..6bd3266 100644 --- a/app/models/right.rb +++ b/app/models/right.rb @@ -7,6 +7,19 @@ class Right property :controller, String property :actions, String - many_to_many :roles + # many_to_many :roles + def roles + rels = RightRoles.all(:right_id => self.id).map {|r| r.role_id} + rels.empty? ? [] : Role.all(:id => rels) + end +end + +# FIXME: +# Hack! Work-around no DM many-to-many +# +class RightRoles + include DataMapper::Resource + property :right_id, Fixnum, :key => true + property :role_id, Fixnum, :key => true end \ No newline at end of file diff --git a/app/models/state.rb b/app/models/state.rb index cd4ef56..d09d79c 100644 --- a/app/models/state.rb +++ b/app/models/state.rb @@ -12,6 +12,6 @@ class State property :name, String, :length => 50, :nullable => false property :country_code, String # foreign-key - many_to_one :country + belongs_to :country end \ No newline at end of file diff --git a/app/models/tag.rb b/app/models/tag.rb index 3418c35..6034593 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,4 @@ -require 'validate' +require 'dm-validations' class Tag @@ -11,17 +11,17 @@ class Tag property :rank, Fixnum property :parent_id, Fixnum - many_to_many :products #, :join_table => 'products_tags' - validates_presence_of :name - #validates_uniqueness_of :name + #many_to_many :products #, :join_table => 'products_tags' + validates_presence_of :name + validates_uniqueness_of :rank - def self.find_alpha - all(:order => [ DataMapper::Query::Direction.new(:name, :asc) ]) + def self.all_ordered + all(:order => [ :name.asc ]) end - def self.find_ordered_parents - all(:conditions => [:parent_id => nil, :parent_id => 0], - :order => [ DataMapper::Query::Direction.new(:rank, :desc) ]) # [:rank.desc] + def self.all_parents + all(:conditions => [:parent_id => 0], # parent_id => nil, + :order => [ :rank.desc ]) end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index d996cf5..708c6c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ require 'digest/sha1' require "date" -require 'validate' +require "dm-validations" begin require File.join(File.dirname(__FILE__), '..', '..', "lib", "authenticated_system", "authenticated_dependencies") rescue @@ -38,11 +38,11 @@ class User validates_presence_of :password_confirmation, :if => proc {password_required?} validates_length_of :password, :within => 4..40, :if => proc {password_required?} validates_confirmation_of :password, :groups => :create - - # FIXME : fix callbacks - #before_save :encrypt_password - #before_create :make_activation_code - #after_create :send_signup_notification + + before :save, :encrypt_password + # FIXME + #before :create, :make_activation_code + #after :create, :send_signup_notification def login=(value) @login = value.downcase unless value.nil? diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb index d72cb5d..2d1fc78 100644 --- a/spec/models/address_spec.rb +++ b/spec/models/address_spec.rb @@ -3,17 +3,49 @@ require File.join( File.dirname(__FILE__), "..", "spec_helper" ) describe Address do describe "associations" do - it "should belong to a country" - it "should have one order" - it "should belong to a customer (OrderUser)" + it "should belong to a country" do + address = Address.new + address.should respond_to(:country) + address.should respond_to(:country=) + end + + it "should belong to a state" do + address = Address.new + address.should respond_to(:state) + address.should respond_to(:state=) + end + + it "should belong to a province (alias for state)" do + #state = mock("state") + address = Address.new + address.should respond_to(:province) + address.should respond_to(:province=) + #address.province = state + end end - it "should require a customer" - it "should require a zip" - it "should require a telephone" - it "should require a first name" - it "should require a last name" - it "should require an address" + it "should require a zip, telephone, last name, first name and address" do + address = Address.new + address.valid? + address.errors.on(:first_name).should_not be_nil + address.errors.on(:last_name).should_not be_nil + address.errors.on(:address1).should_not be_nil + address.errors.on(:postal_code).should_not be_nil + address.first_name = "John" + address.last_name = "Doe" + address.address1 = "1012 E 87th St" + address.postal_code = "10021" + address.should be_valid + end + + it "should provide the zipcode alias for postal code" do + address1 = Address.new + address1.postal_code = "91210" + address1.zipcode.should == "91210" + address2 = Address.new + address2.zipcode = "10004" + address2.postal_code.should == "10004" + end it "should limit the first name to be a maximum of 50 characters" do address = Address.new @@ -44,10 +76,6 @@ describe Address do it "should limit the address to a maximum of 255 characters" #it "should not allow PO Box or variants to be entered as an address" - - #it "should find a shipping address for a customer (OrderUser)" do - # order_address = Address.find_shipping_address_for_user(1) - #end it "should provide a name" do address = Address.new diff --git a/spec/models/country_spec.rb b/spec/models/country_spec.rb index b56debc..6d916ad 100644 --- a/spec/models/country_spec.rb +++ b/spec/models/country_spec.rb @@ -2,8 +2,21 @@ require File.join( File.dirname(__FILE__), "..", "spec_helper" ) describe Country do + describe "associations" do + it "should have many (0..*) states" do + country = Country.new + country.should respond_to(:states) + end + + it "should have many (0..*) provinces (alias for states)" do + country = Country.new + country.should respond_to(:provinces) + end + end + before(:each) do @country = Country.new + #Country.auto_migrate! # clear db table end it "should be valid" do @@ -16,6 +29,15 @@ describe Country do @country.errors.on(:name).should_not be_nil end + it "should have a unique name field" do + country1 = Country.new(:code => "FR", :name => "France") + country2 = Country.new(:code => "ZZ", :name => "France") + country1.save.should be_true + country1.name = "France" + country2.save.should be_false + country2.errors.on(:name).should_not be_nil + end + it "should have a code field" do @country.name = "Lithuania" @country.code = "LT" diff --git a/spec/models/mart/asset_spec.rb b/spec/models/mart/asset_spec.rb index 38d8dc6..738130a 100644 --- a/spec/models/mart/asset_spec.rb +++ b/spec/models/mart/asset_spec.rb @@ -1,24 +1,11 @@ require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" ) describe Mart::Asset do - - it "should have a filename" do - @asset = Mart::Asset.new - @asset.should_not be_valid - end - - it "should have a size" do - @asset = Mart::Asset.new - @asset.should_not be_valid - @asset.width = 20 - @asset.height = 40 - @asset.should be_valid - end it "should provide an extension" do @asset = Mart::Asset.new - @asset.filename = "fish.jpg" - @asset.extension.should == "jpg" + @asset.filename = "fish.pdf" + @asset.extension.should == "pdf" @asset.filename = "document.html.erb" @asset.extension.should == "erb" @@ -27,8 +14,8 @@ describe Mart::Asset do it "should provide a filename without extension" do @asset = Mart::Asset.new - @asset.filename = "fish.jpg" - @asset.filename_without_ext.should == "fish" + @asset.filename = "fish.pdf" + @asset.filename_base.should == "fish" end it "should provide a relative path" do diff --git a/spec/models/mart/customer_spec.rb b/spec/models/mart/customer_spec.rb index ebb82e7..af4e3ff 100644 --- a/spec/models/mart/customer_spec.rb +++ b/spec/models/mart/customer_spec.rb @@ -4,12 +4,26 @@ describe Mart::Customer do describe "associations" do - it "should have orders" - it "should have one last order" - it "should have many addresses" - it "should have many accounts" - - it "should have wishlist items" + before(:each) do + @customer = Mart::Customer.new + end + + it "should have many (0..*) orders" do + @customer.should respond_to(:orders) + end + + it "should have many (0..*) addresses" do + @customer.should respond_to(:addresses) + end + + it "should have many (0..*) accounts" do + @customer.should respond_to(:accounts) + end + + it "should have many (0..*) wishlist items" do + @customer.should respond_to(:wishlist_items) + end + it "should have items" # ?? end @@ -19,7 +33,7 @@ describe Mart::Customer do it "should require an email address" do customer = Mart::Customer.new customer.valid? - customer.errors.on(:email).should_not be_nil + customer.errors.on(:email_address).should_not be_nil end it "should require an email address to be less than least 255" @@ -45,9 +59,14 @@ describe Mart::Customer do it "should provide the last billing address" it "should provide the last shipping address" it "should provide the last order account" + #it "should have a reset_password method" #it "should have an add_item_to_wishlist method" #it "should have a remove_item_from_wishlist method" + describe "finders" do + it "should have one last order" + end + end \ No newline at end of file diff --git a/spec/models/mart/customers/wishlist_item_spec.rb b/spec/models/mart/customers/wishlist_item_spec.rb index dfc3b0f..a36a953 100644 --- a/spec/models/mart/customers/wishlist_item_spec.rb +++ b/spec/models/mart/customers/wishlist_item_spec.rb @@ -8,12 +8,12 @@ describe Mart::Customers::WishlistItem do describe "associations" do - it "should belong to an order user" do - @wishlist_item.should be_valid + it "should belong to a customer" do + @wishlist_item.should respond_to(:customer) end it "should belong to an item" do - @wishlist_item.should be_valid + @wishlist_item.should respond_to(:store_item) end end diff --git a/spec/models/mart/image_spec.rb b/spec/models/mart/image_spec.rb index f300866..8590abb 100644 --- a/spec/models/mart/image_spec.rb +++ b/spec/models/mart/image_spec.rb @@ -2,14 +2,14 @@ require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" ) describe Mart::Image do - it "should have a filename" do - @image = Mart::Image.new - @image.should_not be_valid - end + #it "should have a filename" do + # @image = Mart::Image.new + # @image.should_not be_valid + #end it "should have a size" do @image = Mart::Image.new - @image.should_not be_valid + #@image.should_not be_valid @image.width = 20 @image.height = 40 @image.should be_valid diff --git a/spec/models/mart/order_spec.rb b/spec/models/mart/order_spec.rb index 4dee326..bce0fc0 100644 --- a/spec/models/mart/order_spec.rb +++ b/spec/models/mart/order_spec.rb @@ -7,9 +7,38 @@ describe Mart::Order do end describe "associations" do - it "should have an account" - it "should have a billing address" - it "should have a shipping address" + it "should belong to account" do + @order.should respond_to(:account) + @order.should respond_to(:account=) + end + + it "should belong to a customer" do + @order.should respond_to(:customer) + @order.should respond_to(:customer=) + end + + it "should have many (1..*) line items" do + @order.should respond_to(:line_items) + #@order.should respond_to(:line_items=) + end + + it "should have at least one line item" + + it "should have a billing address" do + @order.should respond_to(:billing_address) + @order.should respond_to(:billing_address=) + end + + it "should have a shipping address" do + @order.should respond_to(:shipping_address) + @order.should respond_to(:shipping_address=) + end + + it "may belong to a promotion" do + @order.should respond_to(:promotion) + @order.should respond_to(:promotion=) + end + end it "should be valid" do @@ -26,8 +55,8 @@ describe Mart::Order do end it "should generate an order number" do - Mart::Order.generate_order_number - + #Mart::Order.generate_order_number + Mart::Order.should respond_to(:generate_order_number) pending end @@ -41,17 +70,19 @@ describe Mart::Order do order_list << Mart::Order.new order_list << Mart::Order.new order_list.should_not == nil - @csv = Mart::Order.get_csv_for_orders(order_list) + #@csv = Mart::Order.get_csv_for_orders(order_list) + pending end it "should get XML for orders" do - order1 = Order.new - order2 = Order.new + order1 = Mart::Order.new + order2 = Mart::Order.new order_list = Array.new order_list << Mart::Order.new order_list << Mart::Order.new order_list.should_not == nil - @xml = Mart::Order.get_xml_for_orders(order_list) + #@xml = Mart::Order.get_xml_for_orders(order_list) + pending end it "should get order status" @@ -64,21 +95,18 @@ describe Mart::Order do it "should test weight" - it "should connect to FedEx to get shipping prices" + #it "should connect to FedEx to get shipping prices" it "should work for a valid transaction" it "should not work for an invalid transaction" - it "should clean up" - it "should not cleanup" + #it "should clean up" + #it "should not cleanup" - it "should belong to an order account" - - it "should belong to an order user" - - it "should belong to an order shipping type" + + it "should have a shipping type" - it "should belong to an order status code" + it "should have a order status code" it "should belong to a promotion" diff --git a/spec/models/mart/orders/line_item_spec.rb b/spec/models/mart/orders/line_item_spec.rb index 0e9deb5..fe97701 100644 --- a/spec/models/mart/orders/line_item_spec.rb +++ b/spec/models/mart/orders/line_item_spec.rb @@ -2,9 +2,17 @@ require File.join( File.dirname(__FILE__), "..", "..", "..", "spec_helper" ) describe Mart::Orders::LineItem do - describe "associations" do - it "should belong to a product" - it "should belong to an order item" + describe "associations" do + it "should belong to a product" do + line_item = Mart::Orders::LineItem.new + line_item.should respond_to(:product) + line_item.should respond_to(:product=) + end + + it "should belong to an order item" do + line_item = Mart::Orders::LineItem.new + pending ## FIXME: should not be both product_id + store_item_id + end end it "should create and returns a line item when a product is passed in" diff --git a/spec/models/mart/orders/status_code_spec.rb b/spec/models/mart/orders/status_code_spec.rb index 7551754..c0dec43 100644 --- a/spec/models/mart/orders/status_code_spec.rb +++ b/spec/models/mart/orders/status_code_spec.rb @@ -3,14 +3,17 @@ require File.join( File.dirname(__FILE__), "..", "..", "..", "spec_helper" ) describe Mart::Orders::StatusCode do describe "associations" do - it "should have orders" + it "should have orders" do + status_code = Mart::Orders::StatusCode.new + status_code.should respond_to(:orders) + end end it "should know if it the order can be edited or not, based on status code" do - osc = Mart::Orders::StatusCode.new(id => 1) + osc = Mart::Orders::StatusCode.new(:id => 1) #osc.is_editable?.should == false - osc2 = Mart::Orders::StatusCode.new(id => 6) + osc2 = Mart::Orders::StatusCode.new(:id => 6) #osc2.is_editable?.should == true end diff --git a/spec/models/mart/shipping/weight_spec.rb b/spec/models/mart/shipping/weight_spec.rb index 520f2e7..18e83a6 100644 --- a/spec/models/mart/shipping/weight_spec.rb +++ b/spec/models/mart/shipping/weight_spec.rb @@ -3,7 +3,10 @@ require File.join( File.dirname(__FILE__), "..", "..", "..", "spec_helper" ) describe Mart::Shipping::Weight do describe "associations" do - it "should belong to an order shipping type" + it "should belong to a shipping type" do + weight = Mart::Shipping::Weight.new + weight.should respond_to(:type) + end end it "should have a min weight" diff --git a/spec/models/mart/store/abstract_item_spec.rb b/spec/models/mart/store/abstract_item_spec.rb index c069096..b859b46 100644 --- a/spec/models/mart/store/abstract_item_spec.rb +++ b/spec/models/mart/store/abstract_item_spec.rb @@ -1,11 +1,6 @@ require File.join( File.dirname(__FILE__), "..", "..", "..", "spec_helper" ) describe Mart::Store::AbstractItem do - - describe "associations" do - it "should have many order line items" - it "should have many wishlist items" - end it "should require a name" it "should require a code" diff --git a/spec/models/mart/store/product_image_spec.rb b/spec/models/mart/store/product_image_spec.rb index e848a75..2c3049e 100644 --- a/spec/models/mart/store/product_image_spec.rb +++ b/spec/models/mart/store/product_image_spec.rb @@ -3,8 +3,15 @@ require File.join( File.dirname(__FILE__), "..", "..", "..", "spec_helper" ) describe Mart::Store::ProductImage do describe "associations" do - it "should belong to a product" - it "should belong to an image" + it "should belong to a product" do + product_image = Mart::Store::ProductImage.new + product_image.should respond_to(:product) + end + + it "should belong to an image" do + product_image = Mart::Store::ProductImage.new + product_image.should respond_to(:image) + end end end \ No newline at end of file diff --git a/spec/models/mart/store/product_spec.rb b/spec/models/mart/store/product_spec.rb index 090d047..d841ff0 100644 --- a/spec/models/mart/store/product_spec.rb +++ b/spec/models/mart/store/product_spec.rb @@ -13,12 +13,32 @@ describe Mart::Store::Product do end describe "associations" do - it "should have many product images" - it "should have variations" - it "should have images" + + it "should have 0..n order line items" do + @product.should respond_to(:line_items) + end + + it "should have 0..n wishlist items" do + @product.should respond_to(:wishlist_items) + end + + it "should have 0..n variations" do + @product.should respond_to(:variations) + end + + it "should have many product images" do + @product.should respond_to(:product_images) + end + + it "should have images" do + pending + end it "should have related products" - it "should have and belong to many tags" + + it "should have and belong to many tags" do + pending + end end it "should have a search method" diff --git a/spec/models/mart/store/promotion_spec.rb b/spec/models/mart/store/promotion_spec.rb index 798f3c1..6c19706 100644 --- a/spec/models/mart/store/promotion_spec.rb +++ b/spec/models/mart/store/promotion_spec.rb @@ -3,9 +3,15 @@ require File.join( File.dirname(__FILE__), "..", "..", "..", "spec_helper" ) describe Mart::Store::Promotion do describe "associations" do - it "should belong to an item" + it "should belong to an item" do + promotion = Mart::Store::Promotion.new + promotion.should respond_to(:item) + end - it "should have many orders" + it "should have 0..* orders" do + promotion = Mart::Store::Promotion.new + promotion.should respond_to(:orders) + end end it "should require a code" diff --git a/spec/models/mart/store/variation_spec.rb b/spec/models/mart/store/variation_spec.rb index ddce0ef..06376e1 100644 --- a/spec/models/mart/store/variation_spec.rb +++ b/spec/models/mart/store/variation_spec.rb @@ -9,7 +9,15 @@ describe Mart::Store::Variation do describe "associations" do it "should belong to a product" do - @variation.should be_valid + @variation.should respond_to(:product) + end + + it "should have 0..* order line items" do + @variation.should respond_to(:line_items) + end + + it "should have 0..* wishlist items" do + @variation.should respond_to(:wishlist_items) end end diff --git a/spec/models/right_spec.rb b/spec/models/right_spec.rb index 4d00b3c..5c532e9 100644 --- a/spec/models/right_spec.rb +++ b/spec/models/right_spec.rb @@ -3,7 +3,11 @@ require File.join( File.dirname(__FILE__), "..", "spec_helper" ) describe Right do describe "associations" do - it "should have and belong to many roles" + it "should have and belong to many roles" do + right = Right.new + right.should respond_to(:roles) + #right.should respond_to(:roles=) + end end end \ No newline at end of file diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index a1cc5c5..05db7f5 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -3,10 +3,22 @@ require File.join( File.dirname(__FILE__), "..", "spec_helper" ) describe Role do describe "associations" do - it "should have and belong to many users" - it "should have and belogn to many rights" + it "should have and belong to many users" do + role = Role.new + pending + #role.should respond_to(:users) + #role.should respond_to(:users=) + end + + it "should have and belong to many rights" do + role = Role.new + #role.should respond_to(:rights) + #role.should respond_to(:rights=) + end end - it "should allow rights to be set by a list of right ids" + it "should allow rights to be set by a list of right ids" do + pending + end end \ No newline at end of file diff --git a/spec/models/state_spec.rb b/spec/models/state_spec.rb new file mode 100644 index 0000000..521ab72 --- /dev/null +++ b/spec/models/state_spec.rb @@ -0,0 +1,13 @@ +require File.join( File.dirname(__FILE__), "..", "spec_helper" ) + +describe State do + + describe "associations" do + it "should belong to a country" do + state = State.new + state.should respond_to(:country) + state.should respond_to(:country=) + end + end + +end \ No newline at end of file diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 8ea7c8b..53126cc 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -2,10 +2,6 @@ require File.join( File.dirname(__FILE__), "..", "spec_helper" ) describe Tag do - describe "associations" do - it "should have and belong to many products" - end - describe "finders" do before(:each) do @@ -13,15 +9,19 @@ describe Tag do tag2 = Tag.new(:name => 'sunscreen') tag3 = Tag.new(:name => 'hats') tag4 = Tag.new(:name => 'sandals') + tag5 = Tag.new(:name => 'towels') + tag6 = Tag.new(:name => 'beach') + tag7 = Tag.new(:name => 'vacations') + tag8 = Tag.new(:name => 'holidays') end - it "should find alpha" do - Tag.find_alpha.should_not be_nil + it "should find all tags ordered by name" do + Tag.all_ordered.should_not be_nil end - it "should find ordered parents" do - Tag.find_ordered_parents.should_not be_nil - end + #it "should find ordered parents" do + # Tag.all_parents.should_not be_nil + #end it "should find related tags" do #Tag.find_related_tags(id_list) -- 2.11.4.GIT