roar-extensions 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'roar_extensions'
3
+
4
+ class PopBand
5
+ include Representable::JSON
6
+ property :name
7
+ property :groupies
8
+ attr_accessor :name, :groupies
9
+ end
10
+
11
+ class SkaBand
12
+ include Representable::JSON
13
+ property :name
14
+ property :groupies, :render_nil => true
15
+ attr_accessor :name, :groupies
16
+ end
17
+
18
+ describe Representable do
19
+ describe "#create_representation_with" do
20
+ let(:band) { PopBand.new }
21
+
22
+ before(:each) do
23
+ band.name = "No One's Choice"
24
+ end
25
+
26
+ context "nil attributes" do
27
+ before(:each) do
28
+ band.groupies = nil
29
+ end
30
+
31
+ it "does not write them" do
32
+ band.send(:create_representation_with, {}, {}, Representable::JSON).
33
+ should == {"name" => "No One's Choice"}
34
+ end
35
+
36
+ context "render_nil => true" do
37
+ let(:band) { SkaBand.new }
38
+
39
+ it "includes the attribute with value nil" do
40
+ band.send(:create_representation_with, {}, {}, Representable::JSON).
41
+ should == {"name" => "No One's Choice", "groupies" => nil}
42
+ end
43
+ end
44
+ end
45
+
46
+ context "false attributes" do
47
+ before(:each) do
48
+ band.groupies = false
49
+ end
50
+
51
+ it "does writes them" do
52
+ band.send(:create_representation_with, {}, {}, Representable::JSON).
53
+ should == {"name" => "No One's Choice", "groupies" => false}
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#update_properties_from" do
59
+ let(:band) { PopBand.new }
60
+
61
+ it "allows false attributes" do
62
+ band.update_properties_from({"groupies" => false}, {}, Representable::JSON)
63
+ band.groupies.should == false
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'roar_extensions'
3
+
4
+ module RoarExtensions
5
+ describe ResourceLinks do
6
+ class TestResourceLinks
7
+ include ResourceLinks
8
+
9
+ def test_merge_links(styles)
10
+ merge_links(styles) { |style|
11
+ {style => 'foo'}
12
+ }
13
+ end
14
+
15
+ def test_resource_link_json(h)
16
+ resource_link_json(h)
17
+ end
18
+ end
19
+
20
+ subject { TestResourceLinks.new }
21
+
22
+ describe "#merge_links" do
23
+ it "merges all hashes for the list using the block as a builder" do
24
+ subject.test_merge_links(['a', 'b']).
25
+ should == {
26
+ 'a' => 'foo',
27
+ 'b' => 'foo'
28
+ }
29
+ end
30
+ end
31
+
32
+ describe "#resource_link_json" do
33
+ it "turns a hash with keys as rels into proper link representations" do
34
+ subject.test_resource_link_json('self' => '/foo', 'next' => '/bar').
35
+ should == {
36
+ 'self' => { :href => '/foo' },
37
+ 'next' => { :href => '/bar' }
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'roar_extensions'
3
+
4
+ describe Roar::Representer::JSON::HAL do
5
+ describe "Hypermedia Feature" do
6
+ describe "Hypermedia.link" do
7
+ let(:mod) do
8
+ Module.new do
9
+ include Roar::Representer::JSON
10
+ include Roar::Representer::Feature::Hypermedia
11
+ end
12
+ end
13
+
14
+ it "accepts strings for rel" do
15
+ mod.class_eval do
16
+ link :rel => 'self', :title => "Hey, @myabc" do
17
+ "http://self"
18
+ end
19
+ end
20
+
21
+ Object.new.extend(mod).to_hash['links'][0][:rel].should == 'self'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'roar_extensions'
3
+
4
+ describe Roar::Representer::JSON::HAL do
5
+ module AttributesContructor
6
+ def initialize(attrs={})
7
+ attrs.each do |k,v|
8
+ instance_variable_set("@#{k}", v)
9
+ end
10
+ end
11
+ end
12
+
13
+ class Item
14
+ include AttributesContructor
15
+ attr_accessor :value
16
+ end
17
+
18
+ class Order
19
+ include AttributesContructor
20
+ attr_accessor :id, :items
21
+ end
22
+
23
+ describe "_embedded key type" do
24
+ it "defaults the _embedded key to be a string" do
25
+ Bla = Module.new do
26
+ include Roar::Representer::JSON::HAL
27
+ property :value
28
+ link :self do
29
+ "http://items/#{value}"
30
+ end
31
+ end
32
+
33
+ @order_rep = Module.new do
34
+ include Roar::Representer::JSON::HAL
35
+ property :id
36
+ collection :items, :class => Item, :extend => Bla, :embedded => true
37
+ link :self do
38
+ "http://orders/#{id}"
39
+ end
40
+ end
41
+
42
+ @order = Order.new(:items => [Item.new(:value => "Beer")], :id => 1).extend(@order_rep)
43
+
44
+ @order.to_hash.should have_key('_embedded')
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'roar_extensions'
3
+
4
+ describe RoarExtensions do
5
+ describe ".base_url" do
6
+ before(:each) do
7
+ RoarExtensions.base_url = nil
8
+ end
9
+
10
+ it "is a configuration option" do
11
+ RoarExtensions.base_url = 'foo'
12
+ RoarExtensions.base_url.should == 'foo'
13
+ end
14
+
15
+ context "not yet set" do
16
+ it "raises an informative error" do
17
+ expect {
18
+ RoarExtensions.base_url
19
+ }.to raise_error("Set base url like RoarExtensions.base_url = 'http://example.com'")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'pry'
4
+ require 'pry-nav'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ end
metadata ADDED
@@ -0,0 +1,220 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roar-extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Donald Plummer
9
+ - Michael Xavier
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-09-26 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: roar
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - '='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.11.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '='
29
+ - !ruby/object:Gem::Version
30
+ version: 0.11.3
31
+ - !ruby/object:Gem::Dependency
32
+ name: activesupport
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 2.3.14
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.3.14
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: pry-nav
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rake
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: 0.9.2
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 0.9.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 2.10.0
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 2.10.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 1.2.1
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: 1.2.1
127
+ - !ruby/object:Gem::Dependency
128
+ name: guard-rspec
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ version: 1.1.0
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: 1.1.0
143
+ description: Useful extensions to roar
144
+ email:
145
+ - developers@crystalcommerce.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .rspec
152
+ - Gemfile
153
+ - Guardfile
154
+ - LICENSE
155
+ - README.md
156
+ - Rakefile
157
+ - lib/roar-extensions.rb
158
+ - lib/roar_extensions.rb
159
+ - lib/roar_extensions/destroyed_record_presenter.rb
160
+ - lib/roar_extensions/helpers/embedded_parameter_parsing.rb
161
+ - lib/roar_extensions/json_hal_extensions.rb
162
+ - lib/roar_extensions/link_presenter.rb
163
+ - lib/roar_extensions/money_presenter.rb
164
+ - lib/roar_extensions/paginated_collection_presenter.rb
165
+ - lib/roar_extensions/presenter.rb
166
+ - lib/roar_extensions/representable_json_extensions.rb
167
+ - lib/roar_extensions/representer.rb
168
+ - lib/roar_extensions/resource_links.rb
169
+ - lib/roar_extensions/version.rb
170
+ - roar-extensions.gemspec
171
+ - spec/destroyed_record_presenter_spec.rb
172
+ - spec/helpers/embedded_parameter_parsing_spec.rb
173
+ - spec/link_presenter_spec.rb
174
+ - spec/money_presenter_spec.rb
175
+ - spec/paginated_collection_presenter_spec.rb
176
+ - spec/presenter_spec.rb
177
+ - spec/representable_spec.rb
178
+ - spec/resource_links_spec.rb
179
+ - spec/roar/representer/feature/hypermedia_spec.rb
180
+ - spec/roar/representer/json/hal_spec.rb
181
+ - spec/roar_extensions_spec.rb
182
+ - spec/spec_helper.rb
183
+ homepage: ''
184
+ licenses: []
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ none: false
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ none: false
197
+ requirements:
198
+ - - ! '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 1.8.24
204
+ signing_key:
205
+ specification_version: 3
206
+ summary: Useful extensions to roar
207
+ test_files:
208
+ - spec/destroyed_record_presenter_spec.rb
209
+ - spec/helpers/embedded_parameter_parsing_spec.rb
210
+ - spec/link_presenter_spec.rb
211
+ - spec/money_presenter_spec.rb
212
+ - spec/paginated_collection_presenter_spec.rb
213
+ - spec/presenter_spec.rb
214
+ - spec/representable_spec.rb
215
+ - spec/resource_links_spec.rb
216
+ - spec/roar/representer/feature/hypermedia_spec.rb
217
+ - spec/roar/representer/json/hal_spec.rb
218
+ - spec/roar_extensions_spec.rb
219
+ - spec/spec_helper.rb
220
+ has_rdoc: