Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect scope of Vcard.configure and Vcard.configuration methods #29

Merged
merged 1 commit into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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