diff --git a/lib/linkedin_url_value.rb b/lib/linkedin_url_value.rb index efc1025..8b0c5b8 100644 --- a/lib/linkedin_url_value.rb +++ b/lib/linkedin_url_value.rb @@ -72,6 +72,10 @@ def regular? def exceptional_errors(errors, attribute, _options = nil) errors.add(attribute, @reason) end + + def to_str + @raw_value.to_s + end end class Regular @@ -86,12 +90,13 @@ def self.cast(val) return val if val.is_a?(Base) return AsBlank.new(val) if val.blank? + val = val.to_str valid_format = valid_linkedin_format?(val) cleaned_url = clean_url(val) return Regular.new(cleaned_url) if valid_format && cleaned_url.include?("https://www.linkedin.com/in/") Exceptional.new(val) - rescue URI::InvalidURIError + rescue URI::InvalidURIError, NoMethodError Exceptional.new(val) end @@ -132,4 +137,4 @@ def self.valid_linkedin_format?(linked_url) end end -require_relative "linkedin_url_value/railtie" if defined?(Rails) && defined?(Rails::Railtie) +require_relative "linkedin_url_value/railtie" if defined?(Rails::Railtie) diff --git a/linkedin_url_value.gemspec b/linkedin_url_value.gemspec index 11cced2..c8ab48b 100644 --- a/linkedin_url_value.gemspec +++ b/linkedin_url_value.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |spec| spec.name = "linkedin_url_value" - spec.version = "0.2.0" + spec.version = "0.2.1" spec.authors = ["Grant Petersen-Speelman"] spec.email = ["grant@nexl.io"] diff --git a/spec/linkedin_url_value_spec.rb b/spec/linkedin_url_value_spec.rb index af9f232..9de377c 100644 --- a/spec/linkedin_url_value_spec.rb +++ b/spec/linkedin_url_value_spec.rb @@ -105,6 +105,12 @@ def cast(*args) expect(first_cast).not_to eql(second_cast) expect([first_cast, second_cast].uniq).to have_attributes(size: 2) end + + it "can be compared with other objects" do # rubocop:disable RSpec/NoExpectationExample + cast(cast(regular_value)).eql?(Object.new) + cast(cast(blank_value)).eql?(Object.new) + cast(cast(exceptional_value)).eql?(Object.new) + end end end