Created
March 1, 2012 16:03
-
-
Save noel/1950786 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 Supplier < ActiveRecord::Base | |
validates :country, :inclusion => { :in => Currency.countries, | |
:message => "Country can only be #{Currency.countries.join(', ')}"} | |
end | |
class Currency < ActiveRecord::Base | |
def self.countries | |
pluck :country | |
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
~/development/supplier_app $ bundle exec rspec spec/models | |
. | |
Finished in 0.11605 seconds | |
1 example, 0 failures | |
~/development/supplier_app $ bundle exec rspec spec | |
F. | |
Failures: | |
1) Supplier Validations: Country needs to be in list of Currencies | |
Failure/Error: good_country_supplier.should be_valid | |
expected valid? to return true, got false | |
# ./spec/models/supplier_spec.rb:49 | |
Finished in 0.678 seconds | |
2 examples, 1 failure | |
Failed examples: | |
rspec ./spec/models/supplier_spec.rb:37 # Supplier Validations: Country needs to be in list of Currencies |
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
its "Country needs to be in list of Currencies" do | |
Currency.create(:country=>"US",:currency=>"USD") | |
good_country_supplier = Supplier.new(:country => "US") | |
good_country_supplier.should be_valid | |
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
~/development/supplier_app $ rails c test | |
Loading test environment (Rails 3.2.1) | |
irb(main):001:0> Currency.pluck :country | |
(0.3ms) SELECT country FROM "currencies" | |
=> ["US"] | |
irb(main):002:0> s = Supplier.new(:country => "US") | |
=> #<Supplier id: nil, company: nil, purchasing_org: "A001", account_group: "0001", name: nil, search_term_1: nil, count | |
ry: "US", language: "E", tax_number_1: "SSN for US OR GST for CA", tax_number_2: "EIN for US OR HST for CA", tax_type: n | |
il, vat: nil, tax_number: "QST for CA", bank_country: nil, bank_key: nil, bank_account: nil, bank_account_holder: nil, b | |
ank_type: "BNK1", recon_account: "200010", payment_terms: nil, check_double_inv: "X", payment_methods: nil, wh_tax_count | |
ry: nil, wh_tax_type: nil, wh_tax_code: nil, liable: nil, rec_type: nil, exemption_number: nil, exemption_pct: nil, exem | |
ption_reason: nil, exemption_from: nil, exemption_to: nil, order_currency: nil, terms_of_payment: nil, incoterms: nil, i | |
ncoterms_2: nil, abc_indicator: nil, created_at: nil, updated_at: nil, good_or_service: nil, payee_type: nil, location_s | |
ervice_performed: nil> | |
irb(main):003:0> s.valid? | |
=> true | |
irb(main):004:0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment