Skip to content

Commit

Permalink
allow all valid options
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Ma committed Mar 25, 2015
1 parent bdff7bb commit 3b4d120
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phony_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module ClassMethods
# you've geocoded before calling this method!
def phony_normalize(*attributes)
options = attributes.last.is_a?(Hash) ? attributes.pop : {}
options.assert_valid_keys :country_code, :default_country_code, :as
options.assert_valid_keys :country_number, :default_country_number, :country_code, :default_country_code, :add_plus, :as
if options[:as].present?
raise ArgumentError, ':as option can not be used on phony_normalize with multiple attribute names! (PhonyRails)' if attributes.size > 1
end
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/phony_rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@
dummy_klass.phony_normalize(:non_existing_attribute)
}.should_not raise_error
end

it "should accept supported options" do
options = [:country_number, :default_country_number, :country_code, :default_country_code, :add_plus, :as]
options.each do |option_sym|
lambda {
dummy_klass.phony_normalize(:phone_number, option_sym => false)
}.should_not raise_error
end
end

it "should not accept unsupported options" do
lambda {
dummy_klass.phony_normalize(:phone_number, unsupported_option: false)
}.should raise_error(ArgumentError)
end
end

describe 'using model#phony_normalized_method' do
Expand Down

0 comments on commit 3b4d120

Please sign in to comment.