morpheus 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +12 -0
- data/.rspec +1 -0
- data/README.md +77 -0
- data/Rakefile +16 -0
- data/lib/morpheus.rb +2 -2
- data/lib/morpheus/base.rb +1 -1
- data/lib/morpheus/client/inflections.rb +1 -1
- data/lib/morpheus/configuration.rb +41 -43
- data/lib/morpheus/errors.rb +1 -1
- data/lib/morpheus/mixins/associations.rb +3 -1
- data/lib/morpheus/mixins/attributes.rb +66 -67
- data/lib/morpheus/mixins/conversion.rb +9 -13
- data/lib/morpheus/mixins/filtering.rb +4 -1
- data/lib/morpheus/mixins/finders.rb +4 -1
- data/lib/morpheus/mixins/introspection.rb +12 -16
- data/lib/morpheus/mixins/persistence.rb +25 -26
- data/lib/morpheus/mixins/reflections.rb +4 -1
- data/lib/morpheus/mixins/request_handling.rb +4 -1
- data/lib/morpheus/mixins/response_parsing.rb +12 -12
- data/lib/morpheus/mixins/url_support.rb +4 -1
- data/lib/morpheus/request.rb +34 -34
- data/lib/morpheus/response.rb +2 -2
- data/lib/morpheus/response_parser.rb +9 -4
- data/lib/morpheus/version.rb +1 -1
- data/morpheus.gemspec +4 -4
- data/spec/dummy/app/resources/author.rb +0 -1
- data/spec/dummy/app/resources/book.rb +0 -1
- data/spec/dummy/app/resources/dog.rb +3 -3
- data/spec/dummy/app/resources/meeting.rb +1 -2
- data/spec/dummy/config/application.rb +7 -36
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/initializers/morpheus.rb +1 -1
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/routes.rb +0 -56
- data/spec/morpheus/associations/association_spec.rb +51 -33
- data/spec/morpheus/associations/belongs_to_association_spec.rb +14 -2
- data/spec/morpheus/associations/has_many_association_spec.rb +31 -11
- data/spec/morpheus/associations/has_one_association_spec.rb +14 -2
- data/spec/morpheus/base_spec.rb +104 -100
- data/spec/morpheus/client/associations_spec.rb +43 -36
- data/spec/morpheus/client/log_subscriber_spec.rb +33 -0
- data/spec/morpheus/client/railtie_spec.rb +5 -0
- data/spec/morpheus/configuration_spec.rb +92 -113
- data/spec/morpheus/mixins/associations_spec.rb +90 -108
- data/spec/morpheus/mixins/attributes_spec.rb +71 -77
- data/spec/morpheus/mixins/conversion_spec.rb +49 -59
- data/spec/morpheus/mixins/filtering_spec.rb +13 -0
- data/spec/morpheus/mixins/finders_spec.rb +180 -217
- data/spec/morpheus/mixins/introspection_spec.rb +81 -124
- data/spec/morpheus/mixins/persistence_spec.rb +140 -133
- data/spec/morpheus/mixins/{reflection_spec.rb → reflections_spec.rb} +28 -28
- data/spec/morpheus/mixins/request_handling_spec.rb +21 -0
- data/spec/morpheus/mixins/response_parsing_spec.rb +10 -2
- data/spec/morpheus/mixins/url_support_spec.rb +29 -0
- data/spec/morpheus/reflection_spec.rb +21 -0
- data/spec/morpheus/relation_spec.rb +34 -58
- data/spec/morpheus/request_cache_spec.rb +33 -2
- data/spec/morpheus/request_queue_spec.rb +37 -0
- data/spec/morpheus/request_spec.rb +102 -1
- data/spec/morpheus/response_parser_spec.rb +17 -0
- data/spec/morpheus/response_spec.rb +55 -51
- data/spec/morpheus/type_caster_spec.rb +128 -118
- data/spec/morpheus/url_builder_spec.rb +41 -0
- data/spec/shared/active_model_lint_test.rb +2 -2
- data/spec/spec_helper.rb +7 -14
- data/spec/support/configuration.rb +3 -4
- metadata +32 -16
- data/README.rdoc +0 -44
- data/autotest/discover.rb +0 -7
- data/lib/morpheus/mock.rb +0 -66
- data/spec/morpheus/mock_spec.rb +0 -133
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Morpheus::UrlBuilder do
|
4
|
+
|
5
|
+
describe '.find_one' do
|
6
|
+
pending
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.find_some' do
|
10
|
+
pending
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.find_all' do
|
14
|
+
pending
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.save' do
|
18
|
+
pending
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.belongs_to' do
|
22
|
+
pending
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.has_one' do
|
26
|
+
pending
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.has_many' do
|
30
|
+
pending
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.relation' do
|
34
|
+
pending
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.destroy' do
|
38
|
+
pending
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
shared_examples_for
|
1
|
+
shared_examples_for 'ActiveModel' do
|
2
2
|
require 'test/unit/assertions'
|
3
3
|
require 'active_model/lint'
|
4
4
|
include Test::Unit::Assertions
|
@@ -11,4 +11,4 @@ shared_examples_for "ActiveModel" do
|
|
11
11
|
ActiveModel::Lint::Tests.public_instance_methods.map { |method| method.to_s }.grep(/^test/).each do |method|
|
12
12
|
example(method.gsub('_', ' ')) { send method }
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,31 +1,24 @@
|
|
1
|
-
|
2
|
-
ENV[
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
3
3
|
|
4
|
-
require File.expand_path(
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
5
|
+
require 'rails/test_help'
|
6
|
+
require 'rspec/rails'
|
7
7
|
|
8
8
|
ActionMailer::Base.delivery_method = :test
|
9
9
|
ActionMailer::Base.perform_deliveries = true
|
10
|
-
ActionMailer::Base.default_url_options[:host] =
|
10
|
+
ActionMailer::Base.default_url_options[:host] = 'test.com'
|
11
11
|
|
12
12
|
Rails.backtrace_cleaner.remove_silencers!
|
13
13
|
|
14
|
-
|
15
|
-
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
|
14
|
+
ActiveRecord::Migrator.migrate File.expand_path('../dummy/db/migrate/', __FILE__)
|
16
15
|
|
17
|
-
# Load support files
|
18
16
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
19
17
|
Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each { |f| require f }
|
20
18
|
|
21
19
|
RSpec.configure do |config|
|
22
|
-
# Remove this line if you don't want RSpec's should and should_not
|
23
|
-
# methods or matchers
|
24
20
|
require 'rspec/expectations'
|
25
21
|
config.include RSpec::Matchers
|
26
|
-
|
27
|
-
# == Mock Framework
|
28
22
|
config.mock_with :rspec
|
29
|
-
|
30
23
|
config.color_enabled = true
|
31
24
|
end
|
@@ -3,21 +3,20 @@ Morpheus::Configuration.hydra = Typhoeus::Hydra.new
|
|
3
3
|
Morpheus::Configuration.allow_net_connect = false
|
4
4
|
|
5
5
|
module MorpheusHelper
|
6
|
-
|
6
|
+
|
7
7
|
def build_morpheus_response(status, content, errors = nil)
|
8
8
|
body = {
|
9
9
|
:status => status,
|
10
10
|
:content => content
|
11
11
|
}
|
12
12
|
body.merge!(errors) if errors
|
13
|
-
Morpheus::Response.new(:code => status, :headers =>
|
13
|
+
Morpheus::Response.new(:code => status, :headers => '', :body => body.to_json, :time => 0.3)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
19
19
|
config.include(MorpheusHelper)
|
20
|
-
|
21
20
|
config.before(:each) do
|
22
21
|
Morpheus::Configuration.hydra.clear_stubs
|
23
22
|
Morpheus::RequestQueue.queue.clear
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpheus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 7
|
10
|
+
version: 0.3.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Moran
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: yajl-ruby
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ">"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
hash: 7
|
61
61
|
segments:
|
@@ -71,7 +71,7 @@ dependencies:
|
|
71
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
hash: 7
|
77
77
|
segments:
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
requirement: &id005 !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - ">"
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
hash: 11
|
93
93
|
segments:
|
@@ -103,7 +103,7 @@ dependencies:
|
|
103
103
|
requirement: &id006 !ruby/object:Gem::Requirement
|
104
104
|
none: false
|
105
105
|
requirements:
|
106
|
-
- -
|
106
|
+
- - ">"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
hash: 7
|
109
109
|
segments:
|
@@ -187,13 +187,14 @@ extensions: []
|
|
187
187
|
extra_rdoc_files: []
|
188
188
|
|
189
189
|
files:
|
190
|
+
- .autotest
|
190
191
|
- .gitignore
|
192
|
+
- .rspec
|
191
193
|
- .rvmrc
|
192
194
|
- Gemfile
|
193
195
|
- LICENSE.txt
|
194
|
-
- README.
|
196
|
+
- README.md
|
195
197
|
- Rakefile
|
196
|
-
- autotest/discover.rb
|
197
198
|
- lib/ext/typhoeus.rb
|
198
199
|
- lib/morpheus.rb
|
199
200
|
- lib/morpheus/associations/association.rb
|
@@ -219,7 +220,6 @@ files:
|
|
219
220
|
- lib/morpheus/mixins/request_handling.rb
|
220
221
|
- lib/morpheus/mixins/response_parsing.rb
|
221
222
|
- lib/morpheus/mixins/url_support.rb
|
222
|
-
- lib/morpheus/mock.rb
|
223
223
|
- lib/morpheus/reflection.rb
|
224
224
|
- lib/morpheus/relation.rb
|
225
225
|
- lib/morpheus/request.rb
|
@@ -276,21 +276,29 @@ files:
|
|
276
276
|
- spec/morpheus/associations/has_one_association_spec.rb
|
277
277
|
- spec/morpheus/base_spec.rb
|
278
278
|
- spec/morpheus/client/associations_spec.rb
|
279
|
+
- spec/morpheus/client/log_subscriber_spec.rb
|
280
|
+
- spec/morpheus/client/railtie_spec.rb
|
279
281
|
- spec/morpheus/configuration_spec.rb
|
280
282
|
- spec/morpheus/mixins/associations_spec.rb
|
281
283
|
- spec/morpheus/mixins/attributes_spec.rb
|
282
284
|
- spec/morpheus/mixins/conversion_spec.rb
|
285
|
+
- spec/morpheus/mixins/filtering_spec.rb
|
283
286
|
- spec/morpheus/mixins/finders_spec.rb
|
284
287
|
- spec/morpheus/mixins/introspection_spec.rb
|
285
288
|
- spec/morpheus/mixins/persistence_spec.rb
|
286
|
-
- spec/morpheus/mixins/
|
289
|
+
- spec/morpheus/mixins/reflections_spec.rb
|
290
|
+
- spec/morpheus/mixins/request_handling_spec.rb
|
287
291
|
- spec/morpheus/mixins/response_parsing_spec.rb
|
288
|
-
- spec/morpheus/
|
292
|
+
- spec/morpheus/mixins/url_support_spec.rb
|
293
|
+
- spec/morpheus/reflection_spec.rb
|
289
294
|
- spec/morpheus/relation_spec.rb
|
290
295
|
- spec/morpheus/request_cache_spec.rb
|
296
|
+
- spec/morpheus/request_queue_spec.rb
|
291
297
|
- spec/morpheus/request_spec.rb
|
298
|
+
- spec/morpheus/response_parser_spec.rb
|
292
299
|
- spec/morpheus/response_spec.rb
|
293
300
|
- spec/morpheus/type_caster_spec.rb
|
301
|
+
- spec/morpheus/url_builder_spec.rb
|
294
302
|
- spec/shared/active_model_lint_test.rb
|
295
303
|
- spec/spec_helper.rb
|
296
304
|
- spec/support/configuration.rb
|
@@ -323,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
323
331
|
requirements: []
|
324
332
|
|
325
333
|
rubyforge_project:
|
326
|
-
rubygems_version: 1.8.
|
334
|
+
rubygems_version: 1.8.13
|
327
335
|
signing_key:
|
328
336
|
specification_version: 3
|
329
337
|
summary: RESTful API Client
|
@@ -373,21 +381,29 @@ test_files:
|
|
373
381
|
- spec/morpheus/associations/has_one_association_spec.rb
|
374
382
|
- spec/morpheus/base_spec.rb
|
375
383
|
- spec/morpheus/client/associations_spec.rb
|
384
|
+
- spec/morpheus/client/log_subscriber_spec.rb
|
385
|
+
- spec/morpheus/client/railtie_spec.rb
|
376
386
|
- spec/morpheus/configuration_spec.rb
|
377
387
|
- spec/morpheus/mixins/associations_spec.rb
|
378
388
|
- spec/morpheus/mixins/attributes_spec.rb
|
379
389
|
- spec/morpheus/mixins/conversion_spec.rb
|
390
|
+
- spec/morpheus/mixins/filtering_spec.rb
|
380
391
|
- spec/morpheus/mixins/finders_spec.rb
|
381
392
|
- spec/morpheus/mixins/introspection_spec.rb
|
382
393
|
- spec/morpheus/mixins/persistence_spec.rb
|
383
|
-
- spec/morpheus/mixins/
|
394
|
+
- spec/morpheus/mixins/reflections_spec.rb
|
395
|
+
- spec/morpheus/mixins/request_handling_spec.rb
|
384
396
|
- spec/morpheus/mixins/response_parsing_spec.rb
|
385
|
-
- spec/morpheus/
|
397
|
+
- spec/morpheus/mixins/url_support_spec.rb
|
398
|
+
- spec/morpheus/reflection_spec.rb
|
386
399
|
- spec/morpheus/relation_spec.rb
|
387
400
|
- spec/morpheus/request_cache_spec.rb
|
401
|
+
- spec/morpheus/request_queue_spec.rb
|
388
402
|
- spec/morpheus/request_spec.rb
|
403
|
+
- spec/morpheus/response_parser_spec.rb
|
389
404
|
- spec/morpheus/response_spec.rb
|
390
405
|
- spec/morpheus/type_caster_spec.rb
|
406
|
+
- spec/morpheus/url_builder_spec.rb
|
391
407
|
- spec/shared/active_model_lint_test.rb
|
392
408
|
- spec/spec_helper.rb
|
393
409
|
- spec/support/configuration.rb
|
data/README.rdoc
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
= RESTful API Client
|
2
|
-
Working toward a DSL that is very ActiveResource/ActiveRecord-like with some features stolen from other great libraries like DataMapper.
|
3
|
-
|
4
|
-
For Example:
|
5
|
-
|
6
|
-
class Dummy < PolarisResource::Base
|
7
|
-
property :name
|
8
|
-
property :created_at
|
9
|
-
property :has_smarts
|
10
|
-
|
11
|
-
belongs_to :thingy
|
12
|
-
has_many :thingamabobs
|
13
|
-
has_one :doohickey
|
14
|
-
end
|
15
|
-
|
16
|
-
@dummy = Dummy.new(
|
17
|
-
:name => "Dumb",
|
18
|
-
:has_smarts => false,
|
19
|
-
:thingy_id => 2) # => #<Dummy:0x1016858d8>
|
20
|
-
@dummy.new_record? # => true
|
21
|
-
@dummy.save # => POST http://localhost/dummies
|
22
|
-
|
23
|
-
@dummy = Dummy.find(1) # => GET http:localhost/dummies/1
|
24
|
-
@dummy.new_record? # => false
|
25
|
-
@dummy.name # => "Dumb"
|
26
|
-
@dummy.name = "Dumber" # => "Dumber"
|
27
|
-
@dummy.save # => PUT http://localhost/dummies/1
|
28
|
-
@dummy.update_attributes(:has_smarts => true) # => PUT http://localhost/dummies/1
|
29
|
-
|
30
|
-
@dummy.thingy # => GET http://localhost/thingies/2
|
31
|
-
@dummy.thingamabobs # => GET http://localhost/dummies/1/thingamabobs
|
32
|
-
@dummy.doohickey # => GET http://localhost/dummies/1/doohickey
|
33
|
-
|
34
|
-
Dummy.all # => GET http://localhost/dummies
|
35
|
-
Dummy.find(1,2,3) # => GET http://localhost/dummies?ids=1,2,3
|
36
|
-
Dummy.find([1,2,3]) # => GET http://localhost/dummies?ids=1,2,3
|
37
|
-
|
38
|
-
Dummy.where(:name => "Dumb") # => GET http://localhost/dummies?name=Dumb
|
39
|
-
Dummy.where(:name => "Dumb", :has_smarts => false) # => GET http://localhost/dummies?name=Dumb&has_smarts=false
|
40
|
-
Dummy.limit(1) # => GET http://localhost/dummies?limit=1
|
41
|
-
Dummy.result_per_page = 25 # => 25
|
42
|
-
Dummy.page(3) # => GET http://localhost/dummies?limit=25&offset=50
|
43
|
-
|
44
|
-
Design informed by Service-Oriented Design with Ruby and Rails by Paul Dix, @Amazon[http://www.amazon.com/Service-Oriented-Design-Rails-Addison-Wesley-Professional/dp/0321659368]
|
data/autotest/discover.rb
DELETED
data/lib/morpheus/mock.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# The Mock class is used to mock out single instances of a remote resource.
|
2
|
-
# It will stub any requests to /:class_name/:id.
|
3
|
-
module Morpheus
|
4
|
-
class Mock
|
5
|
-
|
6
|
-
def initialize(mock_class, id, attributes = {}, options = {})
|
7
|
-
@mock_class = mock_class.to_s
|
8
|
-
@attributes = HashWithIndifferentAccess.new(attributes).merge({ 'id' => id })
|
9
|
-
@options = options
|
10
|
-
|
11
|
-
@attributes.keys.each do |attribute|
|
12
|
-
(class << self; self; end).class_eval do
|
13
|
-
define_method attribute do
|
14
|
-
@attributes[attribute]
|
15
|
-
end
|
16
|
-
|
17
|
-
define_method "#{attribute}=" do |value|
|
18
|
-
@attributes[attribute] = value
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
stub_finder_methods!
|
24
|
-
end
|
25
|
-
|
26
|
-
def id
|
27
|
-
@attributes[:id]
|
28
|
-
end
|
29
|
-
|
30
|
-
def status
|
31
|
-
@options[:status] || 200
|
32
|
-
end
|
33
|
-
|
34
|
-
def ==(other_object)
|
35
|
-
HashWithIndifferentAccess.new(other_object.attributes) == @attributes && other_object.class.to_s == @mock_class
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.mock(mock_class, id, attributes = {}, options = {})
|
39
|
-
new(mock_class, id, attributes, options)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.clear!
|
43
|
-
Configuration.hydra.clear_stubs
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def stub_finder_methods!
|
49
|
-
stub_find_one!
|
50
|
-
end
|
51
|
-
|
52
|
-
def stub_find_one!
|
53
|
-
response = Morpheus::Response.new(:code => status, :headers => "", :body => stub_find_one_body, :time => 0.3)
|
54
|
-
Configuration.hydra.stub(:get, find_one_uri).and_return(response)
|
55
|
-
end
|
56
|
-
|
57
|
-
def stub_find_one_body
|
58
|
-
{ :status => status, :content => @attributes.merge({ :id => 1 }) }.to_json
|
59
|
-
end
|
60
|
-
|
61
|
-
def find_one_uri
|
62
|
-
"#{Configuration.host}/#{@mock_class.underscore.pluralize}/#{id}"
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
data/spec/morpheus/mock_spec.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class Fake
|
4
|
-
def self.attributes
|
5
|
-
{
|
6
|
-
:string => "Test",
|
7
|
-
:boolean => true,
|
8
|
-
:datetime => 'May 14, 2011, 5:00PM',
|
9
|
-
:time => 'May 14, 2011, 5:00PM',
|
10
|
-
:date => 'May 14, 2011',
|
11
|
-
:array => [1,2,3],
|
12
|
-
:hash => { :one => 1, :two => "two" }
|
13
|
-
}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe Morpheus::Mock, ".initialize" do
|
18
|
-
|
19
|
-
before(:each) do
|
20
|
-
@mock = Morpheus::Mock.new(Fake, 1, Fake.attributes)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "sets the @mock_class variable to the class passed in as a string" do
|
24
|
-
@mock.instance_variable_get('@mock_class').should eql("Fake")
|
25
|
-
end
|
26
|
-
|
27
|
-
it "creates a new instance of this mock class with the given id" do
|
28
|
-
@mock.id.should eql(1)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "sets the @attributes variable using the attributes and id passed in" do
|
32
|
-
@mock.instance_variable_get('@attributes').should eql(HashWithIndifferentAccess.new(Fake.attributes.merge({ :id => 1 })))
|
33
|
-
end
|
34
|
-
|
35
|
-
it "creates attr_accessors for each attribute" do
|
36
|
-
@mock.instance_variable_get('@attributes').keys.each do |key|
|
37
|
-
@mock.should respond_to(key)
|
38
|
-
@mock.should respond_to("#{key}=")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "stubs the find method by stubbing the find url at '/:mock_class/:id'" do
|
43
|
-
body = {
|
44
|
-
:status => 200,
|
45
|
-
:content => Fake.attributes.merge({ :id => 1 })
|
46
|
-
}.to_json
|
47
|
-
response = Typhoeus::Response.new(:code => 200, :headers => "", :body => body, :time => 0.3)
|
48
|
-
@test_stub = Typhoeus::HydraMock.new("#{Morpheus::Configuration.host}/fakes/1", :get)
|
49
|
-
@test_stub.and_return(response)
|
50
|
-
@stub = Morpheus::Configuration.hydra.stubs.find do |stub|
|
51
|
-
stub.url == @test_stub.url
|
52
|
-
end
|
53
|
-
@stub.should be_matches(Typhoeus::Request.new("#{Morpheus::Configuration.host}/fakes/1", :method => :get))
|
54
|
-
Yajl::Parser.parse(@stub.response.body).should eql(Yajl::Parser.parse(@test_stub.response.body))
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when given a specific status code" do
|
58
|
-
|
59
|
-
before(:each) do
|
60
|
-
Morpheus::Mock.clear!
|
61
|
-
Morpheus::Mock.new(Fake, 1, Fake.attributes, :status => 500)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns a response with the given status code" do
|
65
|
-
Morpheus::Configuration.hydra.should eql(Typhoeus::Hydra.hydra)
|
66
|
-
response = Typhoeus::Request.get("#{Morpheus::Configuration.host}/fakes/1")
|
67
|
-
response.code.should eql(500)
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
describe Morpheus::Mock, ".id" do
|
75
|
-
|
76
|
-
before(:each) do
|
77
|
-
@mock = Morpheus::Mock.new(Fake, 1, Fake.attributes)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "returns the id attribute" do
|
81
|
-
@mock.id.should eql(1)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
describe Morpheus::Mock, ".status" do
|
87
|
-
|
88
|
-
context "when a status code has not been set" do
|
89
|
-
|
90
|
-
before(:each) do
|
91
|
-
@mock = Morpheus::Mock.new(Fake, 1, Fake.attributes)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "returns 200" do
|
95
|
-
@mock.status.should eql(200)
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
context "when a status code has been set to 500" do
|
101
|
-
|
102
|
-
before(:each) do
|
103
|
-
@mock = Morpheus::Mock.new(Fake, 1, Fake.attributes, :status => 500)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "returns 500" do
|
107
|
-
@mock.status.should eql(500)
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
describe Morpheus::Mock, "#mock" do
|
115
|
-
|
116
|
-
it "returns a new instance of Mock" do
|
117
|
-
Morpheus::Mock.mock(Fake, 1).should be_a(Morpheus::Mock)
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
describe Morpheus::Mock, "#clear!" do
|
123
|
-
|
124
|
-
it "clears all mock requests from Typhoeus" do
|
125
|
-
Morpheus::Mock.new(Fake, 1, Fake.attributes)
|
126
|
-
Morpheus::Mock.new(Fake, 2, Fake.attributes)
|
127
|
-
Morpheus::Mock.new(Fake, 3, Fake.attributes)
|
128
|
-
Morpheus::Configuration.hydra.stubs.should have(3).stubs
|
129
|
-
Morpheus::Mock.clear!
|
130
|
-
Morpheus::Configuration.hydra.stubs.should be_empty
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|