public
Description: open-source e-commerce built on merb
Clone URL: git://github.com/myabc/merb_mart.git
Click here to lend your support to: merb_mart and make a donation at www.pledgie.com !
Updating to reflect latest changes in DM 0.9

* Removed explicit DataMapper::Validate.
* Insured all models have keys.
* Renamed validation methods to reflect
  changes in dm-validations.
* Made all money-related fields BigDecimals
  (pending availability of custom Money
   DM::Type)
myabc (author)
Sat May 10 13:07:31 -0700 2008
commit  37f3b639f05213d2459ee54a826481d415ac5e00
tree    8ecd970aa3138079e4a414af34d2879f4906f513
parent  f97e83b696c51778e0f79a61877ebda689428069
...
4
5
6
7
8
 
9
10
11
...
20
21
22
23
24
25
26
 
 
 
 
27
28
29
30
 
 
 
31
32
33
...
4
5
6
 
7
8
9
10
11
...
20
21
22
 
 
 
 
23
24
25
26
27
 
 
 
28
29
30
31
32
33
0
@@ -4,8 +4,8 @@
0
 class Address
0
 
0
   include DataMapper::Resource
0
- include DataMapper::Validate
0
 
0
+ property :id, Fixnum, :serial => true
0
   property :first_name, String, :length => 50, :nullable => false
0
   property :last_name, String, :length => 50, :nullable => false
0
   property :company, String, :length => 100
0
@@ -20,14 +20,14 @@ class Address
0
   belongs_to :state
0
   belongs_to :country
0
 
0
- validates_presence_of :first_name
0
- validates_presence_of :last_name
0
- validates_presence_of :address1
0
- validates_presence_of :postal_code
0
+ validates_present :first_name
0
+ validates_present :last_name
0
+ validates_present :address1
0
+ validates_present :postal_code
0
 
0
- validates_length_of :first_name, :maximum => 50
0
- validates_length_of :last_name, :maximum => 50
0
- validates_length_of :address1, :maximum => 255
0
+ validates_length :first_name, :maximum => 50
0
+ validates_length :last_name, :maximum => 50
0
+ validates_length :address1, :maximum => 255
0
 
0
   alias :zipcode :postal_code
0
   alias :zipcode= :postal_code=
...
5
6
7
8
9
10
11
12
13
14
15
16
 
 
17
18
19
...
5
6
7
 
8
9
10
11
12
13
 
 
14
15
16
17
18
0
@@ -5,15 +5,14 @@
0
 class Country
0
   
0
   include DataMapper::Resource
0
- include DataMapper::Validate
0
   
0
   property :code, String, :key => true, :length => 2 # ISO 3166-1 alpha-2
0
   property :name, String, :length => 100, :nullable => false, :unique => true
0
 
0
   has n, :states
0
 
0
- validates_presence_of :name
0
- validates_uniqueness_of :name
0
+ validates_present :name
0
+ validates_is_unique :name
0
 
0
   alias :provinces :states
0
 
...
2
3
4
5
6
7
8
9
10
 
 
 
11
12
13
14
 
15
16
17
...
2
3
4
 
5
 
 
 
 
6
7
8
9
10
11
 
12
13
14
15
0
@@ -2,16 +2,14 @@ module Mart
0
   class AbstractUpload
0
   
0
     include DataMapper::Resource
0
- include DataMapper::Validate
0
 
0
- property :id, Fixnum, :serial => true
0
- property :filename, String
0
- property :created_on, DateTime
0
- #property :parent_id
0
+ property :id, Fixnum, :serial => true
0
+ property :filename, String
0
+ property :created_on, DateTime
0
     property :content_type, String
0
     property :thumbnail, String
0
     property :size, Fixnum
0
- property :type, Class # single-table inheritance
0
+ property :type, Class # single-table inheritance
0
 
0
     def filename_base
0
       filename.split('.').first
...
8
9
10
 
11
12
13
...
8
9
10
11
12
13
14
0
@@ -8,6 +8,7 @@ module Mart
0
       include DataMapper::Validate
0
       require 'ezcrypto'
0
 
0
+ property :id, Fixnum, :serial => true
0
       property :type, Class # single-table inheritance
0
       property :order_id, Fixnum # foreign-key
0
       property :customer_id, Fixnum # foreign-key
...
2
3
4
5
6
7
8
9
...
2
3
4
 
 
5
6
7
0
@@ -2,8 +2,6 @@ module Mart
0
   module Accounts
0
     class BankAccount < AbstractAccount
0
 
0
- #include DataMapper::Resource
0
-
0
       #property :account_subtype, DataMapper::Types::Enum
0
       property :account_number, String
0
       property :routing_number, String, :length => 20
...
2
3
4
5
6
7
8
9
...
2
3
4
 
 
5
6
7
0
@@ -2,8 +2,6 @@ module Mart
0
   module Accounts
0
     class CreditCardAccount < Accounts::AbstractAccount
0
     
0
- #include DataMapper::Resource
0
-
0
       property :cc_number, String
0
       property :expiration_month, Fixnum, :length => 2
0
       property :expiration_year, Fixnum, :length => 4
...
4
5
6
7
8
9
10
...
20
21
22
23
24
 
 
25
26
27
...
4
5
6
 
7
8
9
...
19
20
21
 
 
22
23
24
25
26
0
@@ -4,7 +4,6 @@ module Mart
0
   class Customer
0
   
0
     include DataMapper::Resource
0
- include DataMapper::Validate
0
   
0
     property :id, Fixnum, :serial => true
0
     property :username, String, :length => 50
0
@@ -20,8 +19,8 @@ module Mart
0
     has n, :wishlist_items
0
     # has n, :items, :through => :wishlist_items ## FIXME
0
 
0
- validates_presence_of :email_address
0
- validates_length_of :email_address, :maximum => 255
0
+ validates_present :email_address
0
+ validates_length :email_address, :maximum => 255
0
 
0
     def last_order
0
       # TODO
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+require "bigdecimal"
0
+
0
 module Mart
0
   module Customers
0
     class Cart
...
 
1
2
3
4
5
6
7
8
9
10
...
12
13
14
15
16
17
 
 
 
18
19
20
...
35
36
37
38
 
39
40
41
42
...
1
2
3
4
5
6
7
 
8
9
10
...
12
13
14
 
 
 
15
16
17
18
19
20
...
35
36
37
 
38
39
40
41
42
0
@@ -1,10 +1,10 @@
0
+require "bigdecimal"
0
 require 'dm-validations'
0
 
0
 module Mart
0
   class Order
0
   
0
     include DataMapper::Resource
0
- include DataMapper::Validate
0
 
0
     property :id, Fixnum, :serial => true
0
     property :order_number, Fixnum, :default => 0, :nullable => false, :index => :unique
0
@@ -12,9 +12,9 @@ module Mart
0
     property :shipped_on, DateTime
0
     property :notes, DataMapper::Types::Text
0
     property :referer, String
0
- property :product_cost, Float, :default => 0.0
0
- property :shipping_cost, Float, :default => 0.0
0
- property :tax, Float, :default => 0.0, :nullable => false
0
+ property :product_cost, BigDecimal, :default => 0.0
0
+ property :shipping_cost, BigDecimal, :default => 0.0
0
+ property :tax, Float, :default => 0.0, :nullable => false
0
     property :billing_address_id, Fixnum # foreign-key
0
     property :shipping_address_id, Fixnum # foreign-key
0
     property :account_id, Fixnum # foreign-key
0
@@ -35,7 +35,7 @@ module Mart
0
   
0
     attr_accessor :promotion_code
0
   
0
- validates_presence_of :order_number
0
+ validates_present :order_number
0
   
0
   end
0
 end
0
\ No newline at end of file
...
 
 
1
2
3
4
5
6
7
8
9
 
 
 
10
11
12
...
1
2
3
4
5
6
7
8
 
 
 
9
10
11
12
13
14
0
@@ -1,12 +1,14 @@
0
+require "bigdecimal"
0
+
0
 module Mart
0
   module Orders
0
     class LineItem
0
   
0
       include DataMapper::Resource
0
 
0
- property :id, Fixnum, :serial => true
0
- property :quantity, Fixnum, :default => 0, :nullable => false
0
- property :unit_price, Float, :default => 0.0, :nullable => false
0
+ property :id, Fixnum, :serial => true
0
+ property :quantity, Fixnum, :default => 0, :nullable => false
0
+ property :unit_price, BigDecimal, :default => 0.0, :nullable => false
0
       property :name, String
0
       property :product_id, Fixnum ## FIXME: should not be both product_id + store_item_id
0
       property :store_item_id, Fixnum # foreign-key
...
 
 
1
2
3
4
 
5
6
 
7
8
9
10
11
 
 
 
12
13
14
 
 
15
16
17
 
18
19
20
...
22
23
24
25
 
26
27
28
29
...
1
2
3
4
5
 
6
7
 
8
9
10
 
 
 
11
12
13
14
 
 
15
16
17
18
 
19
20
21
22
...
24
25
26
 
27
28
29
30
31
0
@@ -1,20 +1,22 @@
0
+require "bigdecimal"
0
+
0
 module Mart
0
   module Shipping
0
     class Type
0
-
0
+
0
       include DataMapper::Resource
0
-
0
+
0
       attr_accessor :calculated_price
0
 
0
- property :id, Fixnum, :serial => true
0
- property :name, String, :length => 100, :nullable => false
0
- property :code, String, :length => 50
0
+ property :id, Fixnum, :serial => true
0
+ property :name, String, :length => 100, :nullable => false
0
+ property :code, String, :length => 50
0
       property :is_domestic, TrueClass, :default => true, :nullable => false
0
- property :price, Float, :default => 0.0, :nullable => false
0
-
0
+ property :price, BigDecimal,:default => 0.0, :nullable => false
0
+
0
       has n, :orders
0
       has n, :weights, :class_name => 'OrderShippingWeight' #, :dependent => :destroy
0
-
0
+
0
       def self.get_domestic
0
         all(:is_domestic => true, :order => "price ASC")
0
       end
0
@@ -22,7 +24,7 @@ module Mart
0
       def self.get_foreign
0
         all(:is_domestic => false, :order => "price ASC")
0
       end
0
-
0
+
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
 
 
1
2
3
4
 
5
6
7
8
9
10
 
 
 
 
 
11
12
13
...
1
2
3
4
5
 
6
7
 
 
 
 
 
8
9
10
11
12
13
14
15
0
@@ -1,13 +1,15 @@
0
+require "bigdecimal"
0
+
0
 module Mart
0
   module Shipping
0
     class Weight
0
-
0
+
0
       include DataMapper::Resource
0
-
0
- property :id, Fixnum, :serial => true
0
- property :min_weight, Float, :default => 0.0, :nullable => false
0
- property :max_weight, Float, :default => 0.0, :nullable => false
0
- property :price, Float, :default => 0.0, :nullable => false
0
+
0
+ property :id, Fixnum, :serial => true
0
+ property :min_weight, Float, :default => 0.0, :nullable => false
0
+ property :max_weight, Float, :default => 0.0, :nullable => false
0
+ property :price, BigDecimal, :default => 0.0, :nullable => false
0
       property :order_shipping_type_id, Fixnum # foreign-key
0
 
0
       belongs_to :type
...
 
1
2
3
...
6
7
8
9
10
11
12
13
14
15
 
16
17
18
...
25
26
27
28
 
29
30
31
...
1
2
3
4
...
7
8
9
 
10
11
12
13
14
 
15
16
17
18
...
25
26
27
 
28
29
30
31
0
@@ -1,3 +1,4 @@
0
+require "bigdecimal"
0
 require "date"
0
 require "dm-validations"
0
 
0
@@ -6,13 +7,12 @@ module Mart
0
     class AbstractItem
0
 
0
       include DataMapper::Resource
0
- include DataMapper::Validate
0
 
0
       property :id, Fixnum, :serial => true
0
       property :code, String, :length => 20, :nullable => false
0
       property :name, String, :length => 100, :nullable => false
0
       property :description, DataMapper::Types::Text
0
- property :price, Float, :default => 0.0, :nullable => false
0
+ property :price, BigDecimal, :default => 0.0, :nullable => false
0
       property :date_available, DateTime, :nullable => false
0
       property :quantity, Fixnum, :default => 0, :nullable => false
0
       property :size_width, Float, :default => 0.0, :nullable => false
0
@@ -25,7 +25,7 @@ module Mart
0
       has n, :line_items, :class_name => "Mart::Orders::LineItem"
0
       has n, :wishlist_items, :class_name => "Mart::Customers::WishlistItem" #, :dependent => :destroy
0
       
0
- validates_presence_of :name, :code
0
+ validates_present :name, :code
0
       
0
     end
0
   end
...
 
1
2
3
...
5
6
7
8
9
10
11
12
13
14
 
 
 
 
 
15
16
17
18
19
 
 
20
21
22
 
23
24
25
26
27
28
29
30
 
 
31
32
33
...
1
2
3
4
...
6
7
8
 
9
 
 
 
 
 
10
11
12
13
14
15
16
17
 
 
18
19
20
21
 
22
23
24
25
26
27
28
 
 
29
30
31
32
33
0
@@ -1,3 +1,4 @@
0
+require "bigdecimal"
0
 require 'dm-validations'
0
 
0
 module Mart
0
@@ -5,29 +6,28 @@ module Mart
0
     class Promotion
0
   
0
       include DataMapper::Resource
0
- include DataMapper::Validate
0
 
0
- TYPES = {
0
- 'Dollars' => 0,
0
- 'Percent of total order' => 1,
0
- 'Buy [n] get 1 free' => 2
0
- }
0
+ ## TODO: add support for subtypes:
0
+ # - dollars off
0
+ # - percetnage off
0
+ # - buy n, get n free
0
+ # -
0
   
0
       property :id, Fixnum, :serial => true
0
       property :code, String, :length => 15, :nullable => false
0
- property :discount_type, Fixnum, :default => 0, :nullable => false
0
- property :discount_amount, Float, :default => 0.0, :nullable => false
0
+ property :discount_type, Fixnum, :default => 0, :nullable => false
0
+ property :discount_amount, BigDecimal, :default => 0.0, :nullable => false
0
       property :start, DateTime, :nullable => false
0
       property :end, DateTime, :nullable => false
0
- property :minimum_cart_value, Float
0
+ property :minimum_cart_value, BigDecimal
0
       property :description, String, :nullable => false
0
       property :store_item_id, Fixnum # foreign-key
0
 
0
       has n, :orders
0
       belongs_to :item, :class_name => "Mart::Store::AbstractItem"
0
   
0
- validates_presence_of :code, :discount_amount, :discount_type, :description
0
- validates_numericalnes_of :discount_amount
0
+ validates_present :code, :discount_amount, :discount_type, :description
0
+ validates_is_number :discount_amount
0
 
0
     end
0
   end
...
5
6
7
8
9
10
11
12
13
14
15
 
 
16
17
18
...
5
6
7
 
8
9
10
11
12
 
 
13
14
15
16
17
0
@@ -5,14 +5,13 @@ require 'dm-validations'
0
 class Tag
0
   
0
   include DataMapper::Resource
0
- include DataMapper::Validate
0
   
0
   property :id, Fixnum, :serial => true
0
   property :name, String, :length => 100, :nullable => false, :key => :unique
0
   property :rank, Fixnum
0
   
0
- validates_presence_of :name
0
- validates_uniqueness_of :rank
0
+ validates_present :name
0
+ validates_is_unique :rank
0
   
0
   def self.all_ordered
0
     all(:order => [ :name.asc ])
...
10
11
12
13
14
15
16
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
 
 
 
 
 
 
 
 
 
 
 
41
42
43
44
 
45
46
47
...
10
11
12
 
13
14
15
...
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
43
44
45
46
0
@@ -10,7 +10,6 @@ end
0
 class User
0
   
0
   include DataMapper::Resource
0
- include DataMapper::Validate
0
   include AuthenticatedSystem::Model
0
   
0
   attr_accessor :password, :password_confirmation
0
@@ -26,22 +25,22 @@ class User
0
   property :remember_token, String
0
   property :created_at, DateTime
0
   property :updated_at, DateTime
0
-
0
- validates_length_of :login, :within => 3..40
0
- validates_uniqueness_of :login
0
- validates_presence_of :email
0
- validates_format_of :email, :as => :email_address
0
- validates_length_of :email, :within => 3..100
0
- validates_uniqueness_of :email
0
- validates_presence_of :password, :if => lambda { |r| r.password_required? }
0
- validates_presence_of :password_confirmation, :if => lambda { |r| r.password_required? }
0
- validates_length_of :password, :within => 4..40, :if => lambda { |r| r.password_required? }
0
- validates_confirmation_of :password#, :groups => :create
0
-
0
+
0
+ validates_length :login, :within => 3..40
0
+ validates_is_unique :login
0
+ validates_present :email
0
+ validates_format :email, :as => :email_address
0
+ validates_length :email, :within => 3..100
0
+ validates_is_unique :email
0
+ validates_present :password, :if => lambda { |r| r.password_required? }
0
+ validates_present :password_confirmation, :if => lambda { |r| r.password_required? }
0
+ validates_length :password, :within => 4..40, :if => lambda { |r| r.password_required? }
0
+ validates_is_confirmed :password#, :groups => :create
0
+
0
   before :save, :encrypt_password
0
   #before_class_method :create, :make_activation_code
0
   #after_class_method :create, :send_signup_notification
0
-
0
+
0
   def login=(value)
0
     @login = value.downcase unless value.nil?
0
   end
...
7
8
9
10
 
11
12
 
 
 
 
13
14
15
16
17
18
19
 
20
21
22
...
26
27
28
29
30
31
32
33
34
35
36
37
38
...
7
8
9
 
10
11
 
12
13
14
15
16
17
18
19
20
21
 
22
23
24
25
...
29
30
31
 
32
33
34
35
36
 
37
38
39
0
@@ -7,16 +7,19 @@ describe Mart::Image do
0
   # @image.should_not be_valid
0
   #end
0
 
0
- it "should have a size" do
0
+ before(:each) do
0
     @image = Mart::Image.new
0
- #@image.should_not be_valid
0
+ end
0
+
0
+ it "should have a size" do
0
+ @image.should_not be_valid
0
     @image.width = 20
0
     @image.height = 40
0
     @image.should be_valid
0
   end
0
   
0
   it "should provide an extension" do
0
- @image = Mart::Image.new
0
+ @image.should be_nil
0
     @image.filename = "fish.jpg"
0
     @image.extension.should == "jpg"
0
     
0
@@ -26,13 +29,11 @@ describe Mart::Image do
0
   end
0
 
0
   it "should provide a filename without extension" do
0
- @image = Mart::Image.new
0
     @image.filename = "fish.jpg"
0
     @image.filename_without_ext.should == "fish"
0
   end
0
   
0
   it "should provide a relative path" do
0
- @image = Mart::Image.new
0
     @image.filename = "a_dogs_life.gif"
0
     @image.relative_path.should == "a_dogs_life.gif"
0
   end

Comments

    No one has commented yet.