morpheus 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
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,44 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Client::Associations, "#belongs_to" do
4
-
5
- it "defines a getter method" do
6
- Purchase.new.should respond_to(:item)
7
- end
3
+ describe Morpheus::Client::Associations do
8
4
 
9
- it "defines a setter method" do
10
- Purchase.new.should respond_to('item=')
11
- end
12
-
13
- context "when the belongs_to association is fulfilled by its contracted 'association_id' attribute" do
14
-
15
- before(:each) do
16
- item = Item.new(:id => 3)
17
- Item.stub(:get).and_return(item)
18
-
19
- @item = Item.find(3)
5
+ describe '.belongs_to_resource' do
6
+ it 'defines a getter method' do
7
+ Purchase.new.should respond_to(:item)
20
8
  end
21
-
22
- it "returns the association object when the id is specified" do
23
- @purchase = Purchase.new
24
- @purchase.item_id = 3
25
- @purchase.item.should be_a(Item)
26
- @purchase.item.id.should eql(3)
27
- end
28
-
29
- it 'can set an association directly' do
30
- @purchase = Purchase.new
31
- @purchase.item = @item
32
- @purchase.item_id.should eql(3)
33
- @purchase.item.should be_a(Item)
34
- @purchase.item.id.should eql(3)
9
+
10
+ it 'defines a setter method' do
11
+ Purchase.new.should respond_to('item=')
35
12
  end
36
-
37
- it "returns nil when the id is not specified" do
38
- @purchase = Purchase.new
39
- @purchase.item.should eql(nil)
13
+
14
+ context 'when the belongs_to association is fulfilled by its contracted "association_id" attribute' do
15
+ before(:each) do
16
+ item = Item.new(:id => 3)
17
+ Item.stub(:get).and_return(item)
18
+ @item = Item.find(3)
19
+ end
20
+
21
+ it 'returns the association object when the id is specified' do
22
+ @purchase = Purchase.new
23
+ @purchase.item_id = 3
24
+ @purchase.item.should be_a(Item)
25
+ @purchase.item.id.should eql(3)
26
+ end
27
+
28
+ it 'can set an association directly' do
29
+ @purchase = Purchase.new
30
+ @purchase.item = @item
31
+ @purchase.item_id.should eql(3)
32
+ @purchase.item.should be_a(Item)
33
+ @purchase.item.id.should eql(3)
34
+ end
35
+
36
+ it 'returns nil when the id is not specified' do
37
+ @purchase = Purchase.new
38
+ @purchase.item.should eql(nil)
39
+ end
40
40
  end
41
-
42
41
  end
43
-
42
+
43
+ describe '.has_many_resources' do
44
+ pending
45
+ end
46
+
47
+ describe '.has_one_resource' do
48
+ pending
49
+ end
50
+
44
51
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morpheus::Client::LogSubscriber do
4
+
5
+ describe '#initialize' do
6
+ pending
7
+ end
8
+
9
+ describe '#request' do
10
+ pending
11
+ end
12
+
13
+ describe '#uncached_request' do
14
+ pending
15
+ end
16
+
17
+ describe '#cached_request' do
18
+ pending
19
+ end
20
+
21
+ describe '#payload' do
22
+ pending
23
+ end
24
+
25
+ describe '#logger' do
26
+ pending
27
+ end
28
+
29
+ describe '#odd?' do
30
+ pending
31
+ end
32
+
33
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morpheus::Client::Railtie do
4
+ pending
5
+ end
@@ -1,136 +1,115 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Configuration, "#host" do
4
-
5
- context "when host has not been set" do
6
-
7
- before(:each) do
8
- Morpheus::Configuration.host = nil
9
- end
10
-
11
- it "raises a ConfigurationError" do
12
- lambda {
13
- Morpheus::Configuration.host
14
- }.should raise_error(Morpheus::ConfigurationError, "The request HOST has not been set. Please set the host using Morpheus::Configuration.host = 'http://www.example.com'")
15
- end
16
-
17
- end
18
-
19
- context "when host has been set" do
20
-
21
- before(:each) do
22
- Morpheus::Configuration.host = "http://localhost:3000"
3
+ describe Morpheus::Configuration do
4
+
5
+ describe '.host' do
6
+ context 'when host has not been set' do
7
+ before(:each) do
8
+ Morpheus::Configuration.host = nil
9
+ end
10
+
11
+ it 'raises a ConfigurationError' do
12
+ lambda {
13
+ Morpheus::Configuration.host
14
+ }.should raise_error(Morpheus::ConfigurationError,
15
+ 'The request HOST has not been set. Please set the host using Morpheus::Configuration.host = "http://www.example.com"')
16
+ end
23
17
  end
24
-
25
- it "returns the host url string" do
26
- Morpheus::Configuration.host.should eql("http://localhost:3000")
18
+
19
+ context 'when host has been set' do
20
+ before(:each) do
21
+ Morpheus::Configuration.host = 'http://localhost:3000'
22
+ end
23
+
24
+ it 'returns the host url string' do
25
+ Morpheus::Configuration.host.should eql('http://localhost:3000')
26
+ end
27
27
  end
28
-
29
28
  end
30
-
31
- end
32
29
 
33
- describe Morpheus::Configuration, "#hydra" do
34
-
35
- context "when hydra has not been set" do
36
-
37
- before(:each) do
38
- Morpheus::Configuration.hydra = nil
30
+ describe '.hydra' do
31
+ context 'when hydra has not been set' do
32
+ before(:each) do
33
+ Morpheus::Configuration.hydra = nil
34
+ end
35
+
36
+ it 'returns the shared Hydra instance from Typhoeus' do
37
+ Morpheus::Configuration.hydra.should eql(Typhoeus::Hydra.hydra)
38
+ end
39
39
  end
40
-
41
- it "returns the shared Hydra instance from Typhoeus" do
42
- Morpheus::Configuration.hydra.should eql(Typhoeus::Hydra.hydra)
40
+
41
+ context 'when hydra has been set' do
42
+ before(:each) do
43
+ @hydra = Typhoeus::Hydra.new
44
+ Morpheus::Configuration.hydra = @hydra
45
+ end
46
+
47
+ it 'returns the specified Typhoeus Hydra instance' do
48
+ Morpheus::Configuration.hydra.should eql(@hydra)
49
+ end
43
50
  end
44
-
45
51
  end
46
-
47
- context "when hydra has been set" do
48
-
49
- before(:each) do
50
- @hydra = Typhoeus::Hydra.new
51
- Morpheus::Configuration.hydra = @hydra
52
+
53
+ describe '.logger' do
54
+ before(:all) do
55
+ @original_logger = Morpheus::Configuration.logger
52
56
  end
53
-
54
- it "returns the specified Typhoeus Hydra instance" do
55
- Morpheus::Configuration.hydra.should eql(@hydra)
57
+
58
+ after(:all) do
59
+ Morpheus::Configuration.logger = @original_logger
56
60
  end
57
-
58
- end
59
-
60
- end
61
61
 
62
- describe Morpheus::Configuration, "#logger" do
63
-
64
- before(:all) do
65
- @original_logger = Morpheus::Configuration.logger
66
- end
67
-
68
- after(:all) do
69
- Morpheus::Configuration.logger = @original_logger
70
- end
71
-
72
- context "when logger has not been set" do
73
-
74
- before(:each) do
75
- Morpheus::Configuration.logger = nil
62
+ context 'when logger has not been set' do
63
+ before(:each) do
64
+ Morpheus::Configuration.logger = nil
65
+ end
66
+
67
+ it 'returns the default Logger instance' do
68
+ Morpheus::Configuration.logger.should be_a(Logger)
69
+ end
76
70
  end
77
-
78
- it "returns the default Logger instance" do
79
- Morpheus::Configuration.logger.should be_a(Logger)
71
+
72
+ context 'when logger has been set' do
73
+ before(:each) do
74
+ @logger = Logger.new(STDOUT)
75
+ Morpheus::Configuration.logger = @logger
76
+ end
77
+
78
+ it 'returns the specified Logger instance' do
79
+ Morpheus::Configuration.logger.should eql(@logger)
80
+ end
80
81
  end
81
-
82
82
  end
83
-
84
- context "when logger has been set" do
85
-
86
- before(:each) do
87
- @logger = Logger.new(STDOUT)
88
- Morpheus::Configuration.logger = @logger
89
- end
90
-
91
- it "returns the specified Logger instance" do
92
- Morpheus::Configuration.logger.should eql(@logger)
83
+
84
+ describe '.allow_net_connect' do
85
+ it 'disables all net connections through Typhoeus' do
86
+ Morpheus::Configuration.allow_net_connect = false
87
+ lambda {
88
+ Typhoeus::Request.get('http://localhost:3000')
89
+ }.should raise_error(Morpheus::NetConnectNotAllowedError)
93
90
  end
94
-
95
91
  end
96
-
97
- end
98
92
 
99
- describe Morpheus::Configuration, "#allow_net_connect" do
100
-
101
- it "disables all net connections through Typhoeus" do
102
- Morpheus::Configuration.allow_net_connect = false
103
- lambda {
104
- Typhoeus::Request.get("http://localhost:3000")
105
- }.should raise_error(Morpheus::NetConnectNotAllowedError)
106
- end
107
-
108
- end
93
+ describe '.allow_net_connect?' do
94
+ context 'when net connect is allowed' do
95
+ before(:each) do
96
+ Morpheus::Configuration.allow_net_connect = true
97
+ end
109
98
 
110
- describe Morpheus::Configuration, "#allow_net_connect?" do
111
-
112
- context "when net connect is allowed" do
113
-
114
- before(:each) do
115
- Morpheus::Configuration.allow_net_connect = true
116
- end
117
-
118
- it "returns true" do
119
- Morpheus::Configuration.should be_allow_net_connect
120
- end
121
-
122
- end
123
-
124
- context "when net connect is not allowed" do
125
-
126
- before(:each) do
127
- Morpheus::Configuration.allow_net_connect = false
99
+ it 'returns true' do
100
+ Morpheus::Configuration.should be_allow_net_connect
101
+ end
128
102
  end
129
-
130
- it "returns true" do
131
- Morpheus::Configuration.should_not be_allow_net_connect
103
+
104
+ context 'when net connect is not allowed' do
105
+ before(:each) do
106
+ Morpheus::Configuration.allow_net_connect = false
107
+ end
108
+
109
+ it 'returns true' do
110
+ Morpheus::Configuration.should_not be_allow_net_connect
111
+ end
132
112
  end
133
-
134
113
  end
135
-
114
+
136
115
  end
@@ -1,141 +1,123 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Associations, "#belongs_to" do
3
+ describe Morpheus::Associations do
4
4
 
5
- it "creates a property for this class matching association name, e.g. belong_to :author # => :author_id" do
6
- Meeting.new.attributes.should include('conference_id')
7
- end
8
-
9
- it "defines a getter method" do
10
- Meeting.new.should respond_to(:conference)
11
- end
12
-
13
- context "when the belongs_to association is fulfilled by its contracted 'association_id' attribute" do
5
+ describe '.belongs_to' do
14
6
 
15
- before(:each) do
16
- meeting = Meeting.new(:id => 1, :conference_id => 2)
17
- meetings = [meeting]
18
- conference = Conference.new(:id => 2)
19
-
20
- Meeting.stub(:get) do |uri, params|
21
- case uri
22
- when '/meetings/1'
23
- meeting
24
- when '/meetings'
25
- meetings
26
- end
27
- end
28
- Conference.stub(:get).and_return(conference)
29
-
30
- @meeting = Meeting.find(1)
7
+ it 'creates a property for this class matching association name, e.g. belong_to :author # => :author_id' do
8
+ Meeting.new.attributes.should include('conference_id')
31
9
  end
32
10
 
33
- it "returns the belongs_to association object" do
34
- @conference = @meeting.conference
35
- @conference.should be_a(Conference)
36
- @conference.id.should eql(2)
37
- @conference.meetings.should include(@meeting)
11
+ it 'defines a getter method' do
12
+ Meeting.new.should respond_to(:conference)
38
13
  end
39
14
 
40
- end
41
-
42
- context "when the belongs_to association is fulfilled by its contracted 'association_id' attribute" do
15
+ context 'when the belongs_to association is fulfilled by its contracted "association_id" attribute' do
16
+ before(:each) do
17
+ meeting = Meeting.new(:id => 1, :conference_id => 2)
18
+ meetings = [meeting]
19
+ conference = Conference.new(:id => 2)
20
+ Meeting.stub(:get) do |uri, params|
21
+ case uri
22
+ when '/meetings/1'
23
+ meeting
24
+ when '/meetings'
25
+ meetings
26
+ end
27
+ end
28
+ Conference.stub(:get).and_return(conference)
43
29
 
44
- before(:each) do
45
- @meeting = Meeting.new
46
- @meeting.conference_id = nil
47
- end
30
+ @meeting = Meeting.find(1)
31
+ end
48
32
 
49
- it "returns nil" do
50
- @meeting.conference.should be_nil
33
+ it 'returns the belongs_to association object' do
34
+ @conference = @meeting.conference
35
+ @conference.should be_a(Conference)
36
+ @conference.id.should eql(2)
37
+ @conference.meetings.should include(@meeting)
38
+ end
51
39
  end
52
40
 
53
- end
54
-
55
- end
56
-
57
- describe Morpheus::Associations, "#has_many" do
58
-
59
- it "creates a getter method" do
60
- Meeting.new.should respond_to(:attendees)
61
- end
62
-
63
- context "when the record has no id" do
64
-
65
- before(:each) do
66
- @meeting = Meeting.new
67
- end
41
+ context 'when the belongs_to association is fulfilled by its contracted "association_id" attribute' do
42
+ before(:each) do
43
+ @meeting = Meeting.new
44
+ @meeting.conference_id = nil
45
+ end
68
46
 
69
- it "returns an empty array" do
70
- @attendees = @meeting.attendees
71
- @attendees.should be_an(Array)
72
- @attendees.should be_empty
47
+ it 'returns nil' do
48
+ @meeting.conference.should be_nil
49
+ end
73
50
  end
74
-
75
51
  end
76
52
 
77
- context "when the record has an id" do
78
-
79
- before(:each) do
80
- meeting = Meeting.new(:id => 1, :conference_id => 2)
81
- attendees = [Attendee.new(:id => 2), Attendee.new(:id => 5)]
82
-
83
- Meeting.stub(:get).and_return(meeting)
84
- Attendee.stub(:get).and_return(attendees)
85
-
86
- @meeting = Meeting.find(1)
53
+ describe '.has_many' do
54
+ it 'creates a getter method' do
55
+ Meeting.new.should respond_to(:attendees)
87
56
  end
88
57
 
89
- it "returns the associated objects" do
90
- @attendees = @meeting.attendees
91
- @attendees.should be_an(Array)
92
- @attendees.should have(2).attendees
93
- @attendees.each do |attendee|
94
- attendee.should be_a(Attendee)
58
+ context 'when the record has no id' do
59
+ before(:each) do
60
+ @meeting = Meeting.new
95
61
  end
96
- end
97
62
 
98
- end
99
-
100
- end
101
-
102
- describe Morpheus::Associations, "#has_one" do
103
-
104
- it "creates a getter method" do
105
- Meeting.new.should respond_to(:speaker)
106
- end
107
-
108
- context "when the record has no id" do
109
-
110
- before(:each) do
111
- @meeting = Meeting.new
63
+ it 'returns an empty array' do
64
+ @attendees = @meeting.attendees
65
+ @attendees.should be_an(Array)
66
+ @attendees.should be_empty
67
+ end
112
68
  end
113
69
 
114
- it "returns nil" do
115
- @meeting.speaker.should be_nil
116
- end
70
+ context 'when the record has an id' do
71
+ before(:each) do
72
+ meeting = Meeting.new(:id => 1, :conference_id => 2)
73
+ attendees = [Attendee.new(:id => 2), Attendee.new(:id => 5)]
74
+ Meeting.stub(:get).and_return(meeting)
75
+ Attendee.stub(:get).and_return(attendees)
76
+ @meeting = Meeting.find(1)
77
+ end
117
78
 
79
+ it 'returns the associated objects' do
80
+ @attendees = @meeting.attendees
81
+ @attendees.should be_an(Array)
82
+ @attendees.should have(2).attendees
83
+ @attendees.each do |attendee|
84
+ attendee.should be_a(Attendee)
85
+ end
86
+ end
87
+ end
118
88
  end
119
89
 
120
- context "when the record has an id" do
121
-
122
- before(:each) do
123
- meeting = Meeting.new(:id => 1, :conference_id => 2)
124
- speakers = [Speaker.new(:id => 5, :meeting_id => 1)]
90
+ describe '.has_one' do
91
+ it 'creates a getter method' do
92
+ Meeting.new.should respond_to(:speaker)
93
+ end
125
94
 
126
- Meeting.stub(:get).and_return(meeting)
127
- Speaker.stub(:get).and_return(speakers)
95
+ context 'when the record has no id' do
96
+ before(:each) do
97
+ @meeting = Meeting.new
98
+ end
128
99
 
129
- @meeting = Meeting.find(1)
100
+ it 'returns nil' do
101
+ @meeting.speaker.should be_nil
102
+ end
130
103
  end
131
104
 
132
- it "returns the association object" do
133
- @speaker = @meeting.speaker
134
- @speaker.should be_a(Speaker)
135
- @speaker.id.should eql(5)
136
- @speaker.meeting.should == @meeting
137
- end
105
+ context 'when the record has an id' do
106
+ before(:each) do
107
+ meeting = Meeting.new(:id => 1, :conference_id => 2)
108
+ speakers = [Speaker.new(:id => 5, :meeting_id => 1)]
109
+ Meeting.stub(:get).and_return(meeting)
110
+ Speaker.stub(:get).and_return(speakers)
111
+ @meeting = Meeting.find(1)
112
+ end
138
113
 
114
+ it 'returns the association object' do
115
+ @speaker = @meeting.speaker
116
+ @speaker.should be_a(Speaker)
117
+ @speaker.id.should eql(5)
118
+ @speaker.meeting.should == @meeting
119
+ end
120
+ end
139
121
  end
140
122
 
141
123
  end