morpheus 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -1
- data/lib/morpheus.rb +3 -23
- data/lib/morpheus/base.rb +11 -11
- data/lib/morpheus/client.rb +10 -0
- data/lib/morpheus/client/associations.rb +6 -6
- data/lib/morpheus/client/cached_request_formatter.rb +20 -0
- data/lib/morpheus/client/log_subscriber.rb +2 -28
- data/lib/morpheus/client/railtie.rb +4 -4
- data/lib/morpheus/client/request_formatter.rb +50 -0
- data/lib/morpheus/client/uncached_request_formatter.rb +40 -0
- data/lib/morpheus/configuration.rb +30 -9
- data/lib/morpheus/mixins.rb +16 -0
- data/lib/morpheus/mixins/associations.rb +39 -37
- data/lib/morpheus/mixins/associations/association.rb +112 -0
- data/lib/morpheus/mixins/associations/belongs_to_association.rb +47 -0
- data/lib/morpheus/mixins/associations/has_many_association.rb +72 -0
- data/lib/morpheus/mixins/associations/has_one_association.rb +48 -0
- data/lib/morpheus/mixins/attributes.rb +97 -95
- data/lib/morpheus/mixins/conversion.rb +16 -14
- data/lib/morpheus/mixins/filtering.rb +13 -11
- data/lib/morpheus/mixins/finders.rb +47 -45
- data/lib/morpheus/mixins/introspection.rb +15 -13
- data/lib/morpheus/mixins/persistence.rb +32 -30
- data/lib/morpheus/mixins/reflections.rb +17 -15
- data/lib/morpheus/mixins/request_handling.rb +27 -25
- data/lib/morpheus/mixins/response_parsing.rb +10 -8
- data/lib/morpheus/mixins/url_support.rb +27 -25
- data/lib/morpheus/reflection.rb +5 -2
- data/lib/morpheus/type_caster.rb +1 -1
- data/lib/morpheus/version.rb +1 -1
- data/morpheus.gemspec +2 -2
- data/spec/dummy/app/resources/book.rb +1 -1
- data/spec/morpheus/base_spec.rb +35 -35
- data/spec/morpheus/client/cached_request_formatter_spec.rb +28 -0
- data/spec/morpheus/client/log_subscriber_spec.rb +53 -10
- data/spec/morpheus/client/request_formatter_spec.rb +5 -0
- data/spec/morpheus/client/uncached_request_formatter_spec.rb +29 -0
- data/spec/morpheus/configuration_spec.rb +49 -11
- data/spec/morpheus/{associations → mixins/associations}/association_spec.rb +1 -1
- data/spec/morpheus/{associations → mixins/associations}/belongs_to_association_spec.rb +1 -1
- data/spec/morpheus/{associations → mixins/associations}/has_many_association_spec.rb +1 -1
- data/spec/morpheus/{associations → mixins/associations}/has_one_association_spec.rb +1 -1
- data/spec/morpheus/mixins/associations_spec.rb +1 -1
- data/spec/morpheus/mixins/attributes_spec.rb +27 -6
- data/spec/morpheus/mixins/conversion_spec.rb +1 -1
- data/spec/morpheus/mixins/filtering_spec.rb +2 -2
- data/spec/morpheus/mixins/finders_spec.rb +1 -1
- data/spec/morpheus/mixins/introspection_spec.rb +1 -1
- data/spec/morpheus/mixins/persistence_spec.rb +1 -1
- data/spec/morpheus/mixins/reflections_spec.rb +1 -1
- data/spec/morpheus/mixins/request_handling_spec.rb +2 -2
- data/spec/morpheus/mixins/response_parsing_spec.rb +2 -2
- data/spec/morpheus/mixins/url_support_spec.rb +2 -2
- data/spec/morpheus/response_parser_spec.rb +5 -1
- data/spec/regressions/sorting_resources_spec.rb +119 -0
- data/spec/spec_helper.rb +3 -2
- metadata +159 -87
- data/lib/morpheus/associations/association.rb +0 -110
- data/lib/morpheus/associations/belongs_to_association.rb +0 -45
- data/lib/morpheus/associations/has_many_association.rb +0 -70
- data/lib/morpheus/associations/has_one_association.rb +0 -46
data/lib/morpheus/reflection.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Morpheus
|
2
2
|
class Reflection
|
3
|
-
attr_reader :macro, :name, :options, :class_name
|
3
|
+
attr_reader :macro, :name, :options, :class_name
|
4
4
|
|
5
5
|
def initialize(macro, name, options = {})
|
6
6
|
@macro = macro
|
7
7
|
@name = name
|
8
8
|
@options = options
|
9
9
|
@class_name = (@options[:class_name] || @name).to_s.singularize.camelize
|
10
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
def klass
|
13
|
+
@klass ||= @class_name.constantize
|
11
14
|
end
|
12
15
|
|
13
16
|
def build_association(*options)
|
data/lib/morpheus/type_caster.rb
CHANGED
data/lib/morpheus/version.rb
CHANGED
data/morpheus.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.email = ['ryan.moran@revolutionprep.com']
|
8
8
|
gem.description = %q{RESTful API Client}
|
9
9
|
gem.summary = %q{RESTful API Client}
|
10
|
-
gem.homepage = ""
|
10
|
+
gem.homepage = "https://github.com/ryanmoran/morpheus"
|
11
11
|
|
12
12
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
13
13
|
gem.files = `git ls-files`.split("\n")
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.version = Morpheus::VERSION
|
18
18
|
|
19
19
|
gem.add_dependency 'yajl-ruby', '~> 1.1.0'
|
20
|
-
gem.add_dependency 'typhoeus', '~> 0.
|
20
|
+
gem.add_dependency 'typhoeus', '~> 0.4.2'
|
21
21
|
gem.add_dependency 'activemodel', '>= 3.0.0'
|
22
22
|
gem.add_dependency 'activesupport', '>= 3.0.0'
|
23
23
|
gem.add_dependency 'i18n', '>= 0.5.0'
|
data/spec/morpheus/base_spec.rb
CHANGED
@@ -7,69 +7,69 @@ describe Morpheus::Base do
|
|
7
7
|
it_behaves_like 'ActiveModel'
|
8
8
|
end
|
9
9
|
|
10
|
-
describe 'implements Morpheus::Associations' do
|
11
|
-
it 'includes the Morpheus::Associations module' do
|
12
|
-
Morpheus::Base.included_modules.should include(Morpheus::Associations)
|
10
|
+
describe 'implements Morpheus::Mixins::Associations' do
|
11
|
+
it 'includes the Morpheus::Mixins::Associations module' do
|
12
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Associations)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe 'implements Morpheus::Attributes' do
|
17
|
-
it 'includes the Morpheus::Attributes module' do
|
18
|
-
Morpheus::Base.included_modules.should include(Morpheus::Attributes)
|
16
|
+
describe 'implements Morpheus::Mixins::Attributes' do
|
17
|
+
it 'includes the Morpheus::Mixins::Attributes module' do
|
18
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Attributes)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe 'implements Morpheus::Conversion' do
|
23
|
-
it 'includes the Morpheus::Conversion module' do
|
24
|
-
Morpheus::Base.included_modules.should include(Morpheus::Conversion)
|
22
|
+
describe 'implements Morpheus::Mixins::Conversion' do
|
23
|
+
it 'includes the Morpheus::Mixins::Conversion module' do
|
24
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Conversion)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe 'implements Morpheus::Filtering' do
|
29
|
-
it 'includes the Morpheus::Filtering module' do
|
30
|
-
Morpheus::Base.included_modules.should include(Morpheus::Filtering)
|
28
|
+
describe 'implements Morpheus::Mixins::Filtering' do
|
29
|
+
it 'includes the Morpheus::Mixins::Filtering module' do
|
30
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Filtering)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe 'implements Morpheus::Finders' do
|
35
|
-
it 'includes the Morpheus::Finders module' do
|
36
|
-
Morpheus::Base.included_modules.should include(Morpheus::Finders)
|
34
|
+
describe 'implements Morpheus::Mixins::Finders' do
|
35
|
+
it 'includes the Morpheus::Mixins::Finders module' do
|
36
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Finders)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe 'implements Morpheus::Introspection' do
|
41
|
-
it 'includes the Morpheus::Introspection module' do
|
42
|
-
Morpheus::Base.included_modules.should include(Morpheus::Introspection)
|
40
|
+
describe 'implements Morpheus::Mixins::Introspection' do
|
41
|
+
it 'includes the Morpheus::Mixins::Introspection module' do
|
42
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Introspection)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe 'implements Morpheus::Persistence' do
|
47
|
-
it 'includes the Morpheus::Persistence module' do
|
48
|
-
Morpheus::Base.included_modules.should include(Morpheus::Persistence)
|
46
|
+
describe 'implements Morpheus::Mixins::Persistence' do
|
47
|
+
it 'includes the Morpheus::Mixins::Persistence module' do
|
48
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Persistence)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
describe 'implements Morpheus::Reflections' do
|
53
|
-
it 'includes the Morpheus::Reflections module' do
|
54
|
-
Morpheus::Base.included_modules.should include(Morpheus::Reflections)
|
52
|
+
describe 'implements Morpheus::Mixins::Reflections' do
|
53
|
+
it 'includes the Morpheus::Mixins::Reflections module' do
|
54
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::Reflections)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe 'implements Morpheus::RequestHandling' do
|
59
|
-
it 'includes the Morpheus::RequestHandling module' do
|
60
|
-
Morpheus::Base.included_modules.should include(Morpheus::RequestHandling)
|
58
|
+
describe 'implements Morpheus::Mixins::RequestHandling' do
|
59
|
+
it 'includes the Morpheus::Mixins::RequestHandling module' do
|
60
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::RequestHandling)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
describe 'implements Morpheus::ResponseParsing' do
|
65
|
-
it 'includes the Morpheus::ResponseParsing module' do
|
66
|
-
Morpheus::Base.included_modules.should include(Morpheus::ResponseParsing)
|
64
|
+
describe 'implements Morpheus::Mixins::ResponseParsing' do
|
65
|
+
it 'includes the Morpheus::Mixins::ResponseParsing module' do
|
66
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::ResponseParsing)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
describe 'implements Morpheus::UrlSupport' do
|
71
|
-
it 'includes the Morpheus::UrlSupport module' do
|
72
|
-
Morpheus::Base.included_modules.should include(Morpheus::UrlSupport)
|
70
|
+
describe 'implements Morpheus::Mixins::UrlSupport' do
|
71
|
+
it 'includes the Morpheus::Mixins::UrlSupport module' do
|
72
|
+
Morpheus::Base.included_modules.should include(Morpheus::Mixins::UrlSupport)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -113,7 +113,7 @@ context 'when an attributes hash is supplied' do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
describe
|
116
|
+
describe '#==' do
|
117
117
|
let(:attributes) { { :id => 1, :name => 'Fido' } }
|
118
118
|
|
119
119
|
context 'when comparing objects that are actually referencing the same memory' do
|
@@ -154,7 +154,7 @@ context 'when an attributes hash is supplied' do
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
describe
|
157
|
+
describe '.base_class' do
|
158
158
|
it 'returns the current class' do
|
159
159
|
Dog.base_class.should eql(Dog)
|
160
160
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Morpheus::Client::CachedRequestFormatter do
|
4
|
+
describe '.call' do
|
5
|
+
let(:subscriber) { ActiveSupport::LogSubscriber.new }
|
6
|
+
let(:event) { mock(:duration => 0.12, :payload => payload) }
|
7
|
+
let(:response) { mock }
|
8
|
+
let(:payload) do
|
9
|
+
{
|
10
|
+
:response => response,
|
11
|
+
:class => Dog,
|
12
|
+
:method => :get,
|
13
|
+
:url => '/dogs',
|
14
|
+
:params => { :name => 'Fido' }
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a formmated string representing the uncached request' do
|
19
|
+
expected = "\e[1m\e[35mCACHE (0.12ms)\e[0m \e[1m/dogs {:name=>\"Fido\"}\e[0m"
|
20
|
+
Morpheus::Client::CachedRequestFormatter.call(subscriber, event, true).should eql(expected)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns a formmated string representing the uncached request' do
|
24
|
+
expected = "\e[1m\e[36mCACHE (0.12ms)\e[0m /dogs {:name=>\"Fido\"}"
|
25
|
+
Morpheus::Client::CachedRequestFormatter.call(subscriber, event, false).should eql(expected)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,33 +1,76 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Morpheus::Client::LogSubscriber do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
let(:subscriber) { Morpheus::Client::LogSubscriber.new }
|
5
|
+
let(:event) { mock(:payload => payload) }
|
6
|
+
let(:payload) { mock }
|
8
7
|
|
9
8
|
describe '#request' do
|
10
|
-
|
9
|
+
let(:payload) { { :response => response } }
|
10
|
+
|
11
|
+
context 'when the event payload contains a cached response' do
|
12
|
+
let(:response) { mock(:cached? => true) }
|
13
|
+
|
14
|
+
it 'calls #cached_request with the event' do
|
15
|
+
subscriber.should_receive(:cached_request).with(event)
|
16
|
+
subscriber.request(event)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when the event payload contains an uncached response' do
|
21
|
+
let(:response) { mock(:cached? => false) }
|
22
|
+
|
23
|
+
it 'calls #uncached_request with the event' do
|
24
|
+
subscriber.should_receive(:uncached_request).with(event)
|
25
|
+
subscriber.request(event)
|
26
|
+
end
|
27
|
+
end
|
11
28
|
end
|
12
29
|
|
13
30
|
describe '#uncached_request' do
|
14
|
-
|
31
|
+
it 'delegates to UncachedRequestFormatter' do
|
32
|
+
Morpheus::Client::UncachedRequestFormatter.should_receive(:call).with(subscriber, event, true)
|
33
|
+
subscriber.uncached_request(event)
|
34
|
+
end
|
15
35
|
end
|
16
36
|
|
17
37
|
describe '#cached_request' do
|
18
|
-
|
38
|
+
it 'delegates to CachedRequestFormatter' do
|
39
|
+
Morpheus::Client::CachedRequestFormatter.should_receive(:call).with(subscriber, event, true)
|
40
|
+
subscriber.cached_request(event)
|
41
|
+
end
|
19
42
|
end
|
20
43
|
|
21
44
|
describe '#payload' do
|
22
|
-
|
45
|
+
context 'when the payload contains :url and :params' do
|
46
|
+
let(:payload) { { :url => '/dogs', :params => { :name => 'fido' } } }
|
47
|
+
|
48
|
+
it 'returns a formatted string with the event :url and :params' do
|
49
|
+
subscriber.payload(event).should eql('/dogs {:name=>"fido"}')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when the payload has no params' do
|
54
|
+
let(:payload) { { :url => '/dogs', :params => {} } }
|
55
|
+
|
56
|
+
it 'returns a formatted string with the event :url' do
|
57
|
+
subscriber.payload(event).should eql('/dogs')
|
58
|
+
end
|
59
|
+
end
|
23
60
|
end
|
24
61
|
|
25
62
|
describe '#logger' do
|
26
|
-
|
63
|
+
it 'returns the Configuration logger' do
|
64
|
+
subscriber.logger.should eql(Morpheus::Configuration.logger)
|
65
|
+
end
|
27
66
|
end
|
28
67
|
|
29
68
|
describe '#odd?' do
|
30
|
-
|
69
|
+
it 'returns an oscillating true/false value every time is is queried' do
|
70
|
+
subscriber.should be_odd
|
71
|
+
subscriber.should_not be_odd
|
72
|
+
subscriber.should be_odd
|
73
|
+
end
|
31
74
|
end
|
32
75
|
|
33
76
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Morpheus::Client::UncachedRequestFormatter do
|
4
|
+
let(:subscriber) { Morpheus::Client::LogSubscriber.new }
|
5
|
+
let(:event) { mock(:payload => payload) }
|
6
|
+
|
7
|
+
describe '.call' do
|
8
|
+
let(:payload) do
|
9
|
+
{
|
10
|
+
:response => response,
|
11
|
+
:class => Dog,
|
12
|
+
:method => :get,
|
13
|
+
:url => '/dogs',
|
14
|
+
:params => { :name => 'Fido' }
|
15
|
+
}
|
16
|
+
end
|
17
|
+
let(:response) { mock(:time => 3.024, :code => 200) }
|
18
|
+
|
19
|
+
it 'returns a formmated string representing the uncached request' do
|
20
|
+
expected = "\e[1m\e[35mDog GET (3024.0ms)\e[0m \e[1m\e[32m[200]\e[0m \e[1m/dogs {:name=>\"Fido\"}\e[0m"
|
21
|
+
Morpheus::Client::UncachedRequestFormatter.call(subscriber, event, true).should eql(expected)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns a formmated string representing the uncached request' do
|
25
|
+
expected = "\e[1m\e[36mDog GET (3024.0ms)\e[0m \e[1m\e[32m[200]\e[0m /dogs {:name=>\"Fido\"}"
|
26
|
+
Morpheus::Client::UncachedRequestFormatter.call(subscriber, event, false).should eql(expected)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -2,11 +2,31 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Morpheus::Configuration do
|
4
4
|
|
5
|
+
describe '.username' do
|
6
|
+
before { @original_username = Morpheus::Configuration.username }
|
7
|
+
after { Morpheus::Configuration.username = @original_username }
|
8
|
+
it 'allows the username to be set and retrieved' do
|
9
|
+
Morpheus::Configuration.username = 'test'
|
10
|
+
Morpheus::Configuration.username.should eql('test')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.password' do
|
15
|
+
before { @original_password = Morpheus::Configuration.password }
|
16
|
+
after { Morpheus::Configuration.password = @original_password }
|
17
|
+
it 'allows the password to be set and retrieved' do
|
18
|
+
Morpheus::Configuration.password = 'test'
|
19
|
+
Morpheus::Configuration.password.should eql('test')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
5
23
|
describe '.host' do
|
6
24
|
context 'when host has not been set' do
|
7
|
-
before
|
25
|
+
before do
|
26
|
+
@original_host = Morpheus::Configuration.host
|
8
27
|
Morpheus::Configuration.host = nil
|
9
28
|
end
|
29
|
+
after { Morpheus::Configuration.host = @original_host }
|
10
30
|
|
11
31
|
it 'raises a ConfigurationError' do
|
12
32
|
lambda {
|
@@ -17,9 +37,11 @@ describe Morpheus::Configuration do
|
|
17
37
|
end
|
18
38
|
|
19
39
|
context 'when host has been set' do
|
20
|
-
before
|
40
|
+
before do
|
41
|
+
@original_host = Morpheus::Configuration.host
|
21
42
|
Morpheus::Configuration.host = 'http://localhost:3000'
|
22
43
|
end
|
44
|
+
after { Morpheus::Configuration.host = @original_host }
|
23
45
|
|
24
46
|
it 'returns the host url string' do
|
25
47
|
Morpheus::Configuration.host.should eql('http://localhost:3000')
|
@@ -29,9 +51,11 @@ describe Morpheus::Configuration do
|
|
29
51
|
|
30
52
|
describe '.hydra' do
|
31
53
|
context 'when hydra has not been set' do
|
32
|
-
before
|
54
|
+
before do
|
55
|
+
@original_hydra = Morpheus::Configuration.hydra
|
33
56
|
Morpheus::Configuration.hydra = nil
|
34
57
|
end
|
58
|
+
after { Morpheus::Configuration.hydra = @original_hydra }
|
35
59
|
|
36
60
|
it 'returns the shared Hydra instance from Typhoeus' do
|
37
61
|
Morpheus::Configuration.hydra.should eql(Typhoeus::Hydra.hydra)
|
@@ -39,10 +63,12 @@ describe Morpheus::Configuration do
|
|
39
63
|
end
|
40
64
|
|
41
65
|
context 'when hydra has been set' do
|
42
|
-
before
|
66
|
+
before do
|
43
67
|
@hydra = Typhoeus::Hydra.new
|
68
|
+
@original_hydra = Morpheus::Configuration.hydra
|
44
69
|
Morpheus::Configuration.hydra = @hydra
|
45
70
|
end
|
71
|
+
after { Morpheus::Configuration.hydra = @original_hydra }
|
46
72
|
|
47
73
|
it 'returns the specified Typhoeus Hydra instance' do
|
48
74
|
Morpheus::Configuration.hydra.should eql(@hydra)
|
@@ -51,11 +77,11 @@ describe Morpheus::Configuration do
|
|
51
77
|
end
|
52
78
|
|
53
79
|
describe '.logger' do
|
54
|
-
before
|
80
|
+
before do
|
55
81
|
@original_logger = Morpheus::Configuration.logger
|
56
82
|
end
|
57
83
|
|
58
|
-
after
|
84
|
+
after do
|
59
85
|
Morpheus::Configuration.logger = @original_logger
|
60
86
|
end
|
61
87
|
|
@@ -70,10 +96,12 @@ describe Morpheus::Configuration do
|
|
70
96
|
end
|
71
97
|
|
72
98
|
context 'when logger has been set' do
|
73
|
-
before
|
99
|
+
before do
|
74
100
|
@logger = Logger.new(STDOUT)
|
101
|
+
@original_logger = Morpheus::Configuration.logger
|
75
102
|
Morpheus::Configuration.logger = @logger
|
76
103
|
end
|
104
|
+
after { Morpheus::Configuration.logger = @original_logger }
|
77
105
|
|
78
106
|
it 'returns the specified Logger instance' do
|
79
107
|
Morpheus::Configuration.logger.should eql(@logger)
|
@@ -82,6 +110,9 @@ describe Morpheus::Configuration do
|
|
82
110
|
end
|
83
111
|
|
84
112
|
describe '.allow_net_connect' do
|
113
|
+
before { @original_allow_net_connect = Morpheus::Configuration.allow_net_connect? }
|
114
|
+
after { Morpheus::Configuration.allow_net_connect = @original_allow_net_connect }
|
115
|
+
|
85
116
|
it 'disables all net connections through Typhoeus' do
|
86
117
|
Morpheus::Configuration.allow_net_connect = false
|
87
118
|
lambda {
|
@@ -92,9 +123,11 @@ describe Morpheus::Configuration do
|
|
92
123
|
|
93
124
|
describe '.allow_net_connect?' do
|
94
125
|
context 'when net connect is allowed' do
|
95
|
-
before
|
126
|
+
before do
|
127
|
+
@original_allow_net_connect = Morpheus::Configuration.allow_net_connect?
|
96
128
|
Morpheus::Configuration.allow_net_connect = true
|
97
129
|
end
|
130
|
+
after { Morpheus::Configuration.allow_net_connect = @original_allow_net_connect }
|
98
131
|
|
99
132
|
it 'returns true' do
|
100
133
|
Morpheus::Configuration.should be_allow_net_connect
|
@@ -102,9 +135,11 @@ describe Morpheus::Configuration do
|
|
102
135
|
end
|
103
136
|
|
104
137
|
context 'when net connect is not allowed' do
|
105
|
-
before
|
138
|
+
before do
|
139
|
+
@original_allow_net_connect = Morpheus::Configuration.allow_net_connect?
|
106
140
|
Morpheus::Configuration.allow_net_connect = false
|
107
141
|
end
|
142
|
+
after { Morpheus::Configuration.allow_net_connect = @original_allow_net_connect }
|
108
143
|
|
109
144
|
it 'returns true' do
|
110
145
|
Morpheus::Configuration.should_not be_allow_net_connect
|
@@ -115,8 +150,11 @@ describe Morpheus::Configuration do
|
|
115
150
|
describe '#parse_error_handler' do
|
116
151
|
let(:handler) { mock }
|
117
152
|
|
118
|
-
before
|
119
|
-
|
153
|
+
before do
|
154
|
+
@original_parse_error_handler = Morpheus::Configuration.parse_error_handler
|
155
|
+
Morpheus::Configuration.parse_error_handler = handler
|
156
|
+
end
|
157
|
+
after { Morpheus::Configuration.parse_error_handler = @original_parse_error_handler }
|
120
158
|
|
121
159
|
it 'allows a Yajl::ParseError handler class to be set' do
|
122
160
|
Morpheus::Configuration.parse_error_handler.should eql(handler)
|