Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2014 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8628107 to your computer and use it in GitHub Desktop.
Save anonymous/8628107 to your computer and use it in GitHub Desktop.
class CreatePurchases < ActiveRecord::Migration
def change
create_table :purchases do |t|
t.string :name
t.integer :shipping_fee
t.timestamps
end
end
end
class Purchase < ActiveRecord::Base
validates :shipping_fee, inclusion: { in: ShippingCharges.all }
end
require 'spec_helper'
describe Purchase do
it { should ensure_inclusion_of(:shipping_fee).in_array(ShippingCharges.all) }
end
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