Created
January 26, 2014 03:46
-
-
Save anonymous/8628107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatePurchases < ActiveRecord::Migration | |
def change | |
create_table :purchases do |t| | |
t.string :name | |
t.integer :shipping_fee | |
t.timestamps | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Purchase < ActiveRecord::Base | |
validates :shipping_fee, inclusion: { in: ShippingCharges.all } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Purchase do | |
it { should ensure_inclusion_of(:shipping_fee).in_array(ShippingCharges.all) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShippingCharges | |
def self.all | |
[0,8,14] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment