Created
August 29, 2011 16:08
-
-
Save ckdake/1178729 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
test "getters/setters for shipping methods should work" do | |
listing = Factory.create(:listing) | |
assert !listing.shipping_methods.include?('CATBUS') | |
assert !listing.ship_via_catbus | |
listing.ship_via_catbus = true | |
assert listing.ship_via_catbus | |
assert listing.shipping_methods.include?('CATBUS') | |
listing.ship_via_catbus = false | |
assert !listing.ship_via_catbus | |
end | |
# Provide getters/setters for shipping methods using method_missing | |
def method_missing(method, *args, &block) | |
if respond_to?(method) | |
super(method, *args, &block) | |
else | |
if matches = method.to_s.match('^ship_via_(\w+)=$') | |
ship_method = $1.upcase | |
self.shipping_methods ||= [] | |
if args[0] == true | |
self.shipping_methods.push(ship_method) unless self.shipping_methods.include?(ship_method) | |
else | |
self.shipping_methods.delete(ship_method) | |
end | |
elsif matches = method.to_s.match('^ship_via_(\w+)$') | |
self.shipping_methods ||= [] | |
self.shipping_methods.include?($1.upcase) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment