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.
Files changed (71) hide show
  1. data/.autotest +12 -0
  2. data/.rspec +1 -0
  3. data/README.md +77 -0
  4. data/Rakefile +16 -0
  5. data/lib/morpheus.rb +2 -2
  6. data/lib/morpheus/base.rb +1 -1
  7. data/lib/morpheus/client/inflections.rb +1 -1
  8. data/lib/morpheus/configuration.rb +41 -43
  9. data/lib/morpheus/errors.rb +1 -1
  10. data/lib/morpheus/mixins/associations.rb +3 -1
  11. data/lib/morpheus/mixins/attributes.rb +66 -67
  12. data/lib/morpheus/mixins/conversion.rb +9 -13
  13. data/lib/morpheus/mixins/filtering.rb +4 -1
  14. data/lib/morpheus/mixins/finders.rb +4 -1
  15. data/lib/morpheus/mixins/introspection.rb +12 -16
  16. data/lib/morpheus/mixins/persistence.rb +25 -26
  17. data/lib/morpheus/mixins/reflections.rb +4 -1
  18. data/lib/morpheus/mixins/request_handling.rb +4 -1
  19. data/lib/morpheus/mixins/response_parsing.rb +12 -12
  20. data/lib/morpheus/mixins/url_support.rb +4 -1
  21. data/lib/morpheus/request.rb +34 -34
  22. data/lib/morpheus/response.rb +2 -2
  23. data/lib/morpheus/response_parser.rb +9 -4
  24. data/lib/morpheus/version.rb +1 -1
  25. data/morpheus.gemspec +4 -4
  26. data/spec/dummy/app/resources/author.rb +0 -1
  27. data/spec/dummy/app/resources/book.rb +0 -1
  28. data/spec/dummy/app/resources/dog.rb +3 -3
  29. data/spec/dummy/app/resources/meeting.rb +1 -2
  30. data/spec/dummy/config/application.rb +7 -36
  31. data/spec/dummy/config/environments/production.rb +1 -1
  32. data/spec/dummy/config/initializers/morpheus.rb +1 -1
  33. data/spec/dummy/config/locales/en.yml +1 -1
  34. data/spec/dummy/config/routes.rb +0 -56
  35. data/spec/morpheus/associations/association_spec.rb +51 -33
  36. data/spec/morpheus/associations/belongs_to_association_spec.rb +14 -2
  37. data/spec/morpheus/associations/has_many_association_spec.rb +31 -11
  38. data/spec/morpheus/associations/has_one_association_spec.rb +14 -2
  39. data/spec/morpheus/base_spec.rb +104 -100
  40. data/spec/morpheus/client/associations_spec.rb +43 -36
  41. data/spec/morpheus/client/log_subscriber_spec.rb +33 -0
  42. data/spec/morpheus/client/railtie_spec.rb +5 -0
  43. data/spec/morpheus/configuration_spec.rb +92 -113
  44. data/spec/morpheus/mixins/associations_spec.rb +90 -108
  45. data/spec/morpheus/mixins/attributes_spec.rb +71 -77
  46. data/spec/morpheus/mixins/conversion_spec.rb +49 -59
  47. data/spec/morpheus/mixins/filtering_spec.rb +13 -0
  48. data/spec/morpheus/mixins/finders_spec.rb +180 -217
  49. data/spec/morpheus/mixins/introspection_spec.rb +81 -124
  50. data/spec/morpheus/mixins/persistence_spec.rb +140 -133
  51. data/spec/morpheus/mixins/{reflection_spec.rb → reflections_spec.rb} +28 -28
  52. data/spec/morpheus/mixins/request_handling_spec.rb +21 -0
  53. data/spec/morpheus/mixins/response_parsing_spec.rb +10 -2
  54. data/spec/morpheus/mixins/url_support_spec.rb +29 -0
  55. data/spec/morpheus/reflection_spec.rb +21 -0
  56. data/spec/morpheus/relation_spec.rb +34 -58
  57. data/spec/morpheus/request_cache_spec.rb +33 -2
  58. data/spec/morpheus/request_queue_spec.rb +37 -0
  59. data/spec/morpheus/request_spec.rb +102 -1
  60. data/spec/morpheus/response_parser_spec.rb +17 -0
  61. data/spec/morpheus/response_spec.rb +55 -51
  62. data/spec/morpheus/type_caster_spec.rb +128 -118
  63. data/spec/morpheus/url_builder_spec.rb +41 -0
  64. data/spec/shared/active_model_lint_test.rb +2 -2
  65. data/spec/spec_helper.rb +7 -14
  66. data/spec/support/configuration.rb +3 -4
  67. metadata +32 -16
  68. data/README.rdoc +0 -44
  69. data/autotest/discover.rb +0 -7
  70. data/lib/morpheus/mock.rb +0 -66
  71. data/spec/morpheus/mock_spec.rb +0 -133
@@ -1,99 +1,93 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Attributes, "#property" do
4
-
5
- it "defines setter and getter methods for the given property" do
6
- @book = Book.new
7
- @book.should respond_to(:title)
8
- @book.title = "Test Title"
9
- @book.title.should eql("Test Title")
10
- end
11
-
12
- it "creates an attribute entry for this property" do
13
- Book.new.attributes.should include(:title)
3
+ describe Morpheus::Attributes do
4
+
5
+ describe '.property' do
6
+ it 'defines setter and getter methods for the given property' do
7
+ @book = Book.new
8
+ @book.should respond_to(:title)
9
+ @book.title = 'Test Title'
10
+ @book.title.should eql('Test Title')
11
+ end
12
+
13
+ it 'creates an attribute entry for this property' do
14
+ Book.new.attributes.should include(:title)
15
+ end
14
16
  end
15
-
16
- end
17
17
 
18
- describe Morpheus::Attributes, "#default_attributes" do
19
-
20
- it "returns the default attributes has which will be applied as the attributes when a new object is instantiated" do
21
- Book.default_attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :title => nil, :author_id => nil }))
18
+ describe '.default_attributes' do
19
+ it 'returns the default attributes has which will be applied as the attributes when a new object is instantiated' do
20
+ Book.default_attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :title => nil, :author_id => nil }))
21
+ end
22
22
  end
23
-
24
- end
25
23
 
26
- describe Morpheus::Attributes, "#typecast_attributes" do
27
- pending
28
- end
24
+ describe '.typecast_attributes' do
25
+ pending
26
+ end
29
27
 
30
- describe Morpheus::Attributes, "#attribute_defined?" do
31
- pending
32
- end
28
+ describe '.attribute_defined?' do
29
+ pending
30
+ end
33
31
 
34
- describe Morpheus::Attributes, ".attributes" do
35
-
36
- it "returns the attributes hash" do
37
- Book.new.attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :title => nil, :author_id => nil }))
32
+ describe '#attributes' do
33
+ it 'returns the attributes hash' do
34
+ Book.new.attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :title => nil, :author_id => nil }))
35
+ end
38
36
  end
39
-
40
- end
41
37
 
42
- describe Morpheus::Attributes, ".read_attribute_for_validation" do
43
- pending
44
- end
38
+ describe '#read_attribute_for_validation' do
39
+ pending
40
+ end
45
41
 
46
- describe Morpheus::Attributes, ".typecast" do
47
- pending
48
- end
42
+ describe '#typecast' do
43
+ pending
44
+ end
49
45
 
50
- describe Morpheus::Attributes, ".attributes_without_id" do
51
- pending
52
- end
46
+ describe '#attributes_without_basic_attributes' do
47
+ pending
48
+ end
53
49
 
54
- describe Morpheus::Attributes, ".update_attribute" do
55
-
56
- it "updates the attribute with the given value" do
57
- @book = Book.new(:title => "Horton Hears a Who")
58
- @book.title.should eql("Horton Hears a Who")
59
- @book.update_attribute(:title, "Red Fish, Blue Fish, One Fish, Two Fish")
60
- @book.title.should eql("Red Fish, Blue Fish, One Fish, Two Fish")
50
+ describe "#update_attribute" do
51
+ it 'updates the attribute with the given value' do
52
+ @book = Book.new(:title => 'Horton Hears a Who')
53
+ @book.title.should eql('Horton Hears a Who')
54
+ @book.update_attribute(:title, 'One Fish, Two Fish, Red Fish, Blue Fish')
55
+ @book.title.should eql('One Fish, Two Fish, Red Fish, Blue Fish')
56
+ end
61
57
  end
62
-
63
- end
64
58
 
65
- describe Morpheus::Attributes, ".merge_attributes" do
66
-
67
- it "updates each attribute with the given value" do
68
- @book = Book.new(:title => "Green Eggs and Ham")
69
- @book.id.should be_nil
70
- @book.title.should eql("Green Eggs and Ham")
71
- @book.send(:merge_attributes, { :title => "Red Fish, Blue Fish, One Fish, Two Fish", :id => 5 })
72
- @book.id.should eql(5)
73
- @book.title.should eql("Red Fish, Blue Fish, One Fish, Two Fish")
59
+ describe '#update_reflection' do
60
+ pending
74
61
  end
75
-
76
- end
77
62
 
78
- describe Morpheus::Attributes, "dirty tracking" do
79
-
80
- it "includes the ActiveModel::Validations module" do
81
- Morpheus::Base.included_modules.should include(ActiveModel::Dirty)
63
+ describe '#merge_attributes' do
64
+ it 'updates each attribute with the given value' do
65
+ @book = Book.new(:title => 'Green Eggs and Ham')
66
+ @book.id.should be_nil
67
+ @book.title.should eql('Green Eggs and Ham')
68
+ @book.send(:merge_attributes, { :title => 'One Fish, Two Fish, Red Fish, Blue Fish', :id => 5 })
69
+ @book.id.should eql(5)
70
+ @book.title.should eql('One Fish, Two Fish, Red Fish, Blue Fish')
71
+ end
82
72
  end
83
-
84
- it "tracks dirty state for property values" do
85
- @book = Book.new
86
- @book.should_not be_title_changed
87
- @book.title = "Dirty title"
88
- @book.should be_title_changed
73
+
74
+ describe 'dirty tracking' do
75
+ it 'includes the ActiveModel::Dirty module' do
76
+ Morpheus::Base.included_modules.should include(ActiveModel::Dirty)
77
+ end
78
+
79
+ it 'tracks dirty state for property values' do
80
+ @book = Book.new
81
+ @book.should_not be_title_changed
82
+ @book.title = 'Dirty title'
83
+ @book.should be_title_changed
84
+ end
89
85
  end
90
-
91
- end
92
86
 
93
- describe Morpheus::Attributes, "validations" do
94
-
95
- it "includes the ActiveModel::Validations module" do
96
- Morpheus::Base.included_modules.should include(ActiveModel::Validations)
87
+ describe 'validations' do
88
+ it 'includes the ActiveModel::Validations module' do
89
+ Morpheus::Base.included_modules.should include(ActiveModel::Validations)
90
+ end
97
91
  end
98
-
92
+
99
93
  end
@@ -1,76 +1,66 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Conversion, ".to_model" do
4
-
5
- before(:each) do
6
- @dog = Dog.new
7
- end
8
-
9
- it "returns this object" do
10
- @dog.to_model.should eql(@dog)
11
- end
12
-
13
- end
3
+ describe Morpheus::Conversion do
14
4
 
15
- describe Morpheus::Conversion, ".to_param" do
16
-
17
- context "when the id attribute is set" do
18
-
5
+ describe '#to_model' do
19
6
  before(:each) do
20
- Morpheus::Base.stub(:get).and_return(Morpheus::Base.new(:id => 1))
21
- @base = Morpheus::Base.find(1)
7
+ @dog = Dog.new
22
8
  end
23
-
24
- it "returns the id as a string" do
25
- @base.to_param.should eql("1")
26
- end
27
-
28
- end
29
-
30
- context "when the id attribute is set" do
31
-
32
- before(:each) do
33
- @base = Morpheus::Base.new
34
- end
35
-
36
- it "returns the id as a string" do
37
- @base.to_param.should be_nil
9
+
10
+ it 'returns this object' do
11
+ @dog.to_model.should eql(@dog)
38
12
  end
39
-
40
13
  end
41
-
42
- end
43
14
 
44
- describe Morpheus::Conversion, ".to_key" do
45
-
46
- context "when the object is a new record" do
47
-
48
- before(:each) do
49
- @dog = Dog.new(:name => "Daisy", :breed => "English Bulldog", :age => 2)
15
+ describe '#to_param' do
16
+ context 'when the id attribute is set' do
17
+ before(:each) do
18
+ Morpheus::Base.stub(:get).and_return(Morpheus::Base.new(:id => 1))
19
+ @base = Morpheus::Base.find(1)
20
+ end
21
+
22
+ it 'returns the id as a string' do
23
+ @base.to_param.should eql('1')
24
+ end
50
25
  end
51
-
52
- it "returns nil" do
53
- @dog.to_key.should be_nil
26
+
27
+ context 'when the id attribute is set' do
28
+ before(:each) do
29
+ @base = Morpheus::Base.new
30
+ end
31
+
32
+ it 'returns the id as a string' do
33
+ @base.to_param.should be_nil
34
+ end
54
35
  end
55
-
56
36
  end
57
-
58
- context "when the object is persisted" do
59
37
 
60
- before(:each) do
61
- Dog.stub(:get).and_return(Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog", :age => 2))
62
- @dog = Dog.find(1)
38
+ describe '#to_key' do
39
+ context 'when the object is a new record' do
40
+ before(:each) do
41
+ @dog = Dog.new(:name => 'Daisy', :breed => 'English Bulldog', :age => 2)
42
+ end
43
+
44
+ it 'returns nil' do
45
+ @dog.to_key.should be_nil
46
+ end
63
47
  end
64
48
 
65
- it "returns the attribute keys of the object" do
66
- @keys = @dog.to_key
67
- @keys.should have(4).keys
68
- @keys.should include('id')
69
- @keys.should include('name')
70
- @keys.should include('breed')
71
- @keys.should include('age')
49
+ context 'when the object is persisted' do
50
+ before(:each) do
51
+ Dog.stub(:get).and_return(Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog', :age => 2))
52
+ @dog = Dog.find(1)
53
+ end
54
+
55
+ it 'returns the attribute keys of the object' do
56
+ @keys = @dog.to_key
57
+ @keys.should have(4).keys
58
+ @keys.should include('id')
59
+ @keys.should include('name')
60
+ @keys.should include('breed')
61
+ @keys.should include('age')
62
+ end
72
63
  end
73
-
74
64
  end
75
-
65
+
76
66
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morpheus::Filtering do
4
+
5
+ describe '.filter' do
6
+ pending
7
+ end
8
+
9
+ describe '.find_filter' do
10
+ pending
11
+ end
12
+
13
+ end
@@ -1,255 +1,218 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Finders, "#find" do
4
-
5
- context "when the argument is a single integer" do
6
-
7
- context "when this record exists on the external service" do
8
-
9
- before(:each) do
10
- @dog = Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog")
11
- Dog.stub(:get).and_return(@dog)
12
- end
13
-
14
- it "makes a request to /dogs/1 at the external service" do
15
- Dog.should_receive(:get).with("/dogs/1", nil, { :id => 1 }).and_return(@dog)
16
- Dog.find(1)
17
- end
18
-
19
- it "returns the instance representing this found record" do
20
- @dog = Dog.find(1)
21
- @dog.should be_a(Dog)
22
- @dog.id.should eql(1)
23
- @dog.name.should eql("Daisy")
24
- @dog.breed.should eql("English Bulldog")
25
- end
26
-
27
- end
28
-
29
- context "when this record does not exist on the external service" do
30
-
31
- before(:each) do
32
- Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs/1").and_return(build_morpheus_response(404, nil))
3
+ describe Morpheus::Finders do
4
+
5
+ describe '#find' do
6
+ context 'when the argument is a single integer' do
7
+ context 'when this record exists on the external service' do
8
+ before(:each) do
9
+ @dog = Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog')
10
+ Dog.stub(:get).and_return(@dog)
11
+ end
12
+
13
+ it 'makes a request to /dogs/1 at the external service' do
14
+ Dog.should_receive(:get).with('/dogs/1', nil, { :id => 1 }).and_return(@dog)
15
+ Dog.find(1)
16
+ end
17
+
18
+ it 'returns the instance representing this found record' do
19
+ @dog = Dog.find(1)
20
+ @dog.should be_a(Dog)
21
+ @dog.id.should eql(1)
22
+ @dog.name.should eql('Daisy')
23
+ @dog.breed.should eql('English Bulldog')
24
+ end
33
25
  end
34
-
35
- it "raises a ResourceNotFound error" do
36
- lambda { Dog.find(1) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find Dog with ID=1")
26
+
27
+ context 'when this record does not exist on the external service' do
28
+ before(:each) do
29
+ Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs/1").and_return(build_morpheus_response(404, nil))
30
+ end
31
+
32
+ it 'raises a ResourceNotFound error' do
33
+ lambda { Dog.find(1) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find Dog with ID=1")
34
+ end
37
35
  end
38
-
39
36
  end
40
-
41
- end
42
-
43
- context "when the argument is a single array" do
44
-
45
- context "when all records exists on the external service" do
46
-
47
- before(:each) do
48
- @dogs = [
49
- Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog"),
50
- Dog.new(:id => 2, :name => "Wilbur", :breed => "Hounddog"),
51
- Dog.new(:id => 3, :name => "Fido", :breed => "Dalmatian")
52
- ]
53
- Dog.stub(:get).and_return(@dogs)
54
- end
55
-
56
- it "makes a request to /dogs?ids=1,2,3 at the external service" do
57
- Dog.should_receive(:get).with("/dogs", { :ids => [1,2,3] }, { :ids => [1,2,3] }).and_return(@dogs)
58
- Dog.find([1,2,3])
37
+
38
+ context 'when the argument is a single array' do
39
+ context 'when all records exists on the external service' do
40
+ before(:each) do
41
+ @dogs = [
42
+ Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog'),
43
+ Dog.new(:id => 2, :name => 'Wilbur', :breed => 'Hounddog'),
44
+ Dog.new(:id => 3, :name => 'Fido', :breed => 'Dalmatian')
45
+ ]
46
+ Dog.stub(:get).and_return(@dogs)
47
+ end
48
+
49
+ it 'makes a request to /dogs?ids=1,2,3 at the external service' do
50
+ Dog.should_receive(:get).with('/dogs', { :ids => [1,2,3] }, { :ids => [1,2,3] }).and_return(@dogs)
51
+ Dog.find([1,2,3])
52
+ end
53
+
54
+ it 'returns an array of instances representing these found records' do
55
+ @dogs = Dog.find([1,2,3])
56
+ @dogs.should be_an(Array)
57
+ @dogs.should have(3).dogs
58
+ @dogs.each do |dog|
59
+ dog.should be_a(Dog)
60
+ end
61
+ end
59
62
  end
60
-
61
- it "returns an array of instances representing these found records" do
62
- @dogs = Dog.find([1,2,3])
63
- @dogs.should be_an(Array)
64
- @dogs.should have(3).dogs
65
- @dogs.each do |dog|
66
- dog.should be_a(Dog)
63
+
64
+ context 'when there is a requested record that does not exist on the external service' do
65
+ before(:each) do
66
+ Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3").and_return(build_morpheus_response(404, nil))
67
+ end
68
+
69
+ it 'raises a ResourceNotFound error' do
70
+ lambda { Dog.find([1,2,3]) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find all Dogs with IDs (1, 2, 3)")
67
71
  end
68
72
  end
69
-
70
73
  end
71
-
72
- context "when there is a requested record that does not exist on the external service" do
73
-
74
- before(:each) do
75
- Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs?ids=1&ids=2&ids=3").and_return(build_morpheus_response(404, nil))
74
+
75
+ context 'when there are multiple arguments, each being an integer' do
76
+ context 'when all records exists on the external service' do
77
+ before(:each) do
78
+ @dogs = [
79
+ Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog'),
80
+ Dog.new(:id => 2, :name => 'Wilbur', :breed => 'Hounddog'),
81
+ Dog.new(:id => 3, :name => 'Fido', :breed => 'Dalmatian')
82
+ ]
83
+ Dog.stub(:get).and_return(@dogs)
84
+ end
85
+
86
+ it 'makes a request to /dogs?ids=1,2,3 at the external service' do
87
+ Dog.should_receive(:get).with('/dogs', { :ids => [1,2,3] }, { :ids => [1,2,3] }).and_return(@dogs)
88
+ Dog.find(1,2,3)
89
+ end
90
+
91
+ it 'returns an array of instances representing these found records' do
92
+ @dogs = Dog.find(1,2,3)
93
+ @dogs.should be_an(Array)
94
+ @dogs.should have(3).dogs
95
+ @dogs.each do |dog|
96
+ dog.should be_a(Dog)
97
+ end
98
+ end
76
99
  end
77
-
78
- it "raises a ResourceNotFound error" do
79
- lambda { Dog.find([1,2,3]) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find all Dogs with IDs (1, 2, 3)")
100
+
101
+ context 'when there is a requested record that does not exist on the external service' do
102
+ before(:each) do
103
+ Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3").and_return(build_morpheus_response(404, nil))
104
+ end
105
+
106
+ it 'raises a ResourceNotFound error' do
107
+ lambda { Dog.find(1,2,3) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find all Dogs with IDs (1, 2, 3)")
108
+ end
80
109
  end
81
-
82
110
  end
83
-
84
111
  end
85
-
86
- context "when there are multiple arguments, each being an integer" do
87
-
88
- context "when all records exists on the external service" do
89
-
90
- before(:each) do
91
- @dogs = [
92
- Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog"),
93
- Dog.new(:id => 2, :name => "Wilbur", :breed => "Hounddog"),
94
- Dog.new(:id => 3, :name => "Fido", :breed => "Dalmatian")
95
- ]
96
- Dog.stub(:get).and_return(@dogs)
97
- end
98
-
99
- it "makes a request to /dogs?ids=1,2,3 at the external service" do
100
- Dog.should_receive(:get).with("/dogs", { :ids => [1,2,3] }, { :ids => [1,2,3] }).and_return(@dogs)
101
- Dog.find(1,2,3)
102
- end
103
-
104
- it "returns an array of instances representing these found records" do
105
- @dogs = Dog.find(1,2,3)
106
- @dogs.should be_an(Array)
107
- @dogs.should have(3).dogs
108
- @dogs.each do |dog|
109
- dog.should be_a(Dog)
110
- end
111
- end
112
-
112
+
113
+ describe '#all' do
114
+ before(:each) do
115
+ @dogs = [
116
+ Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog'),
117
+ Dog.new(:id => 2, :name => 'Wilbur', :breed => 'Hounddog'),
118
+ Dog.new(:id => 3, :name => 'Fido', :breed => 'Dalmatian')
119
+ ]
120
+ Dog.stub(:get).and_return(@dogs)
113
121
  end
114
-
115
- context "when there is a requested record that does not exist on the external service" do
116
-
117
- before(:each) do
118
- Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs?ids=1&ids=2&ids=3").and_return(build_morpheus_response(404, nil))
119
- end
120
-
121
- it "raises a ResourceNotFound error" do
122
- lambda { Dog.find(1,2,3) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find all Dogs with IDs (1, 2, 3)")
122
+
123
+ it 'returns all found records' do
124
+ @dogs = Dog.all
125
+ @dogs.should be_an(Array)
126
+ @dogs.should have(3).dogs
127
+ @dogs.each do |dog|
128
+ dog.should be_a(Dog)
123
129
  end
124
-
125
130
  end
126
-
127
131
  end
128
-
129
- end
130
132
 
131
- describe Morpheus::Finders, "#all" do
133
+ describe '#first' do
134
+ before(:each) do
135
+ @dogs = [Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog')]
136
+ Dog.stub(:get).and_return(@dogs)
137
+ end
132
138
 
133
- before(:each) do
134
- @dogs = [
135
- Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog"),
136
- Dog.new(:id => 2, :name => "Wilbur", :breed => "Hounddog"),
137
- Dog.new(:id => 3, :name => "Fido", :breed => "Dalmatian")
138
- ]
139
- Dog.stub(:get).and_return(@dogs)
140
- end
141
-
142
- it "returns all found records" do
143
- @dogs = Dog.all
144
- @dogs.should be_an(Array)
145
- @dogs.should have(3).dogs
146
- @dogs.each do |dog|
147
- dog.should be_a(Dog)
139
+ it 'returns first found record' do
140
+ @dog = Dog.first
141
+ @dog.should be_a(Dog)
148
142
  end
149
143
  end
150
144
 
151
- end
152
-
153
- describe Morpheus::Finders, "#first" do
154
-
155
- before(:each) do
156
- @dogs = [Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog")]
157
- Dog.stub(:get).and_return(@dogs)
158
- end
159
-
160
- it "returns first found record" do
161
- @dog = Dog.first
162
- @dog.should be_a(Dog)
163
- end
164
-
165
- end
145
+ describe '#where' do
146
+ context 'when the where attribute is an acceptable attribute' do
147
+ context 'for a where clause with one attribute' do
148
+ before(:each) do
149
+ @dogs = [Dog.new(:name => 'Daisy', :breed => 'English Bulldog').attributes.merge(:id => 1)]
150
+ end
166
151
 
167
- describe Morpheus::Finders, "#where" do
168
-
169
- context "when the where attribute is an acceptable attribute" do
170
-
171
- context "for a where clause with one attribute" do
172
-
173
- before(:each) do
174
- @dogs = [Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1)]
175
- end
176
-
177
- it "makes a request to find all records with the given query parameter" do
178
- Dog.should_receive(:get).with("/dogs", { :name => "Daisy" }).and_return(@dogs)
179
- Dog.where(:name => "Daisy").first
180
- end
181
-
182
- end
183
-
184
- context "for a where clause with multiple attributes" do
185
-
186
- before(:each) do
187
- @dogs = [Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1)]
152
+ it 'makes a request to find all records with the given query parameter' do
153
+ Dog.should_receive(:get).with('/dogs', { :name => 'Daisy' }).and_return(@dogs)
154
+ Dog.where(:name => 'Daisy').first
155
+ end
188
156
  end
189
-
190
- it "makes a request to find all records with the given query parameters" do
191
- Dog.should_receive(:get).with("/dogs", { :breed => "English Bulldog", :name => "Daisy" }).and_return(@dogs)
192
- Dog.where(:name => "Daisy", :breed => "English Bulldog").first
157
+
158
+ context 'for a where clause with multiple attributes' do
159
+ before(:each) do
160
+ @dogs = [Dog.new(:name => 'Daisy', :breed => 'English Bulldog').attributes.merge(:id => 1)]
161
+ end
162
+
163
+ it 'makes a request to find all records with the given query parameters' do
164
+ Dog.should_receive(:get).with('/dogs', { :breed => 'English Bulldog', :name => 'Daisy' }).and_return(@dogs)
165
+ Dog.where(:name => 'Daisy', :breed => 'English Bulldog').first
166
+ end
193
167
  end
194
-
195
168
  end
196
-
197
169
  end
198
-
199
- end
200
170
 
201
- describe Morpheus::Finders, "#limit" do
202
-
203
- before(:each) do
204
- @dogs = [
205
- Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1),
206
- Dog.new(:name => "Wilbur", :breed => "Hounddog").attributes.merge(:id => 2),
207
- Dog.new(:name => "Fido", :breed => "Dalmatian").attributes.merge(:id => 3)
208
- ]
209
- end
171
+ describe '#limit' do
172
+ before(:each) do
173
+ @dogs = [
174
+ Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog'),
175
+ Dog.new(:id => 2, :name => 'Wilbur', :breed => 'Hounddog'),
176
+ Dog.new(:id => 3, :name => 'Fido', :breed => 'Dalmatian')
177
+ ]
178
+ end
210
179
 
211
- it "makes a request to find all of the given records, but with a given limit" do
212
- Dog.should_receive(:get).with("/dogs", { :limit => 10 }).and_return(@dogs)
213
- Dog.limit(10).all
180
+ it 'makes a request to find all of the given records, but with a given limit' do
181
+ Dog.should_receive(:get).with('/dogs', { :limit => 10 }).and_return(@dogs)
182
+ Dog.limit(10).all
183
+ end
214
184
  end
215
185
 
216
- end
217
-
218
- describe Morpheus::Finders, "#page" do
219
-
220
- before(:each) do
221
- Dog.results_per_page = 10
222
-
223
- @dogs = [
224
- Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1),
225
- Dog.new(:name => "Wilbur", :breed => "Hounddog").attributes.merge(:id => 2),
226
- Dog.new(:name => "Fido", :breed => "Dalmatian").attributes.merge(:id => 3)
227
- ]
228
- end
186
+ describe '#page' do
187
+ before(:each) do
188
+ Dog.results_per_page = 10
189
+ @dogs = [
190
+ Dog.new(:id => 1, :name => 'Daisy', :breed => 'English Bulldog'),
191
+ Dog.new(:id => 2, :name => 'Wilbur', :breed => 'Hounddog'),
192
+ Dog.new(:id => 3, :name => 'Fido', :breed => 'Dalmatian')
193
+ ]
194
+ end
229
195
 
230
- it "makes a request to find all of the given records, but with a given limit and offset" do
231
- Dog.should_receive(:get).with("/dogs", { :limit => 10, :offset => 20 }).and_return(@dogs)
232
- Dog.page(3).all
196
+ it 'makes a request to find all of the given records, but with a given limit and offset' do
197
+ Dog.should_receive(:get).with('/dogs', { :limit => 10, :offset => 20 }).and_return(@dogs)
198
+ Dog.page(3).all
199
+ end
233
200
  end
234
-
235
- end
236
201
 
237
- describe Morpheus::Finders, "#results_per_page" do
238
-
239
- it "defaults to 10" do
240
- Dog.results_per_page.should eql(10)
241
- end
242
-
243
- context "when set to something other than the default" do
244
-
245
- before(:each) do
246
- Dog.results_per_page = 25
202
+ describe '#results_per_page' do
203
+ it 'defaults to 10' do
204
+ Dog.results_per_page.should eql(10)
247
205
  end
248
-
249
- it "returns the number of results to be returned on a page request" do
250
- Dog.results_per_page.should eql(25)
206
+
207
+ context 'when set to something other than the default' do
208
+ before(:each) do
209
+ Dog.results_per_page = 25
210
+ end
211
+
212
+ it 'returns the number of results to be returned on a page request' do
213
+ Dog.results_per_page.should eql(25)
214
+ end
251
215
  end
252
-
253
216
  end
254
-
217
+
255
218
  end