Skip to content

Commit

Permalink
Merge pull request #29 from solenko/master
Browse files Browse the repository at this point in the history
Fix incorrect scope of Vcard.configure and Vcard.configuration methods
  • Loading branch information
brendon authored Nov 29, 2016
2 parents 24f3f63 + f95caaf commit 298f3a5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/vcard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ def self.outer_inner(fields) #:nodoc:
return outer, inner
end

def configuration
def self.configuration
@configuration ||= Configuration.new
end

def configure
def self.configure
yield configuration
end

Expand Down
14 changes: 12 additions & 2 deletions lib/vcard/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ class Configuration
alias_method :ignore_invalid_vcards?, :ignore_invalid_vcards

def initialize
@raise_on_invalid = true
@ignore_invalid_vcard = true
set_default_values
end

def reset
set_default_values
end

private

def set_default_values
@raise_on_invalid_line = true
@ignore_invalid_vcards = true
end

end
Expand Down
23 changes: 23 additions & 0 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "test_helper"

class ConfigurationTest < Test::Unit::TestCase
def test_should_be_an_instance_of_configuration
assert Vcard.configuration.is_a?(::Vcard::Configuration)
end

def test_have_default_values
Vcard.configuration.reset
assert_equal(Vcard.configuration.raise_on_invalid_line, true)
assert_equal(Vcard.configuration.ignore_invalid_vcards, true)
end

def test_allow_configuration_with_block
Vcard.configuration.reset
Vcard.configure do |config|
config.raise_on_invalid_line = false
config.ignore_invalid_vcards = false
end
assert_equal(Vcard.configuration.raise_on_invalid_line, false)
assert_equal(Vcard.configuration.ignore_invalid_vcards, false)
end
end

0 comments on commit 298f3a5

Please sign in to comment.