Permalink
Browse files

customer attributes uses method missing to get attribute readers

  • Loading branch information...
1 parent 2815e8b commit fae799a4c8959332a0866c8d46dcf28a6de4749c @ryanmoran ryanmoran committed Dec 22, 2011
Showing with 22 additions and 11 deletions.
  1. +3 −4 .autotest
  2. +6 −2 lib/netsuite/models/customer.rb
  3. +13 −5 spec/netsuite/models/customer_spec.rb
View
@@ -1,10 +1,9 @@
Autotest.add_hook :initialize do |at|
at.clear_mappings
- at.add_mapping %r%/^lib/(.*)\.rb$% do |_, m|
- possible = File.basename(m[1])
- files_matching %r%^spec/.*(#{possible}_spec)\.rb$%
+ at.add_mapping(%r%^lib/(.*)\.rb$%) do |_, m|
+ at.files_matching %r%^spec/#{m[1]}_spec\.rb$%
end
- at.add_mapping(%r%^spec/.*\_spec.rb$%) {|filename, _| filename }
+ at.add_mapping(%r%^spec/.*\_spec\.rb$%) { |filename, _| filename }
end
@@ -14,8 +14,12 @@ def self.get(id)
end
end
- def is_person
- @attributes[:is_person]
+ def method_missing(m, *args, &block)
+ if @attributes.keys.include?(m.to_sym)
+ @attributes[m.to_sym]
+ else
+ super
+ end
end
end
@@ -27,11 +27,19 @@
end
end
- describe '#is_person' do
- context 'when the customer is a person' do
- it 'returns true' do
- customer = NetSuite::Customer.new(:is_person => true)
- customer.is_person.should be_true
+ describe '#method_missing' do
+ context 'when calling a method that exists as an attribute' do
+ it 'returns the right value from the attributes hash' do
+ customer = NetSuite::Customer.new(:name => 'Mr. Banana')
+ customer.name.should eql('Mr. Banana')
+ end
+ end
+
+ context 'when calling a method that does not exist in the attributes hash' do
+ it 'raises a NoMethodError' do
+ lambda {
+ customer.banana
+ }.should raise_error(NoMethodError)
end
end
end

0 comments on commit fae799a

Please sign in to comment.