roar-extensions 0.0.2 → 0.0.3

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.
@@ -0,0 +1,7 @@
1
+ module RoarExtensions::HypermediaExtensions
2
+ def marshal_dump
3
+ super.stringify_keys
4
+ end
5
+ end
6
+
7
+ Roar::Representer::Feature::Hypermedia::Hyperlink.send(:include, RoarExtensions::HypermediaExtensions)
@@ -16,8 +16,8 @@ class RoarExtensions::LinkPresenter
16
16
  def to_hash(*args)
17
17
  {
18
18
  rel => {
19
- :href => href,
20
- :title => title
19
+ 'href' => href,
20
+ 'title' => title
21
21
  }.delete_if {|k,v| v.nil? || v.empty?}
22
22
  }
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module RoarExtensions
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -17,6 +17,7 @@ end
17
17
 
18
18
  require 'active_support'
19
19
  require 'active_support/core_ext/module'
20
+ require 'active_support/core_ext/hash/keys'
20
21
 
21
22
  require 'roar_extensions/helpers/embedded_parameter_parsing'
22
23
  require 'roar_extensions/json_hal_extensions'
@@ -28,3 +29,4 @@ require 'roar_extensions/link_presenter'
28
29
  require 'roar_extensions/money_presenter'
29
30
  require 'roar_extensions/paginated_collection_presenter'
30
31
  require 'roar_extensions/resource_links'
32
+ require 'roar_extensions/hypermedia_extensions'
@@ -19,7 +19,7 @@ module RoarExtensions
19
19
 
20
20
  context "no title" do
21
21
  its(:as_json) do
22
- should == { 'search_engine' => {:href => 'http://google.com'} }
22
+ should == { 'search_engine' => {'href' => 'http://google.com'} }
23
23
  end
24
24
 
25
25
  it "aliases to_hash to as_json" do
@@ -29,13 +29,13 @@ module RoarExtensions
29
29
 
30
30
  context "title given" do
31
31
  subject { LinkPresenter.new('search_engine',
32
- 'http://google.com',
33
- 'Cool Search') }
32
+ 'http://google.com',
33
+ 'Cool Search') }
34
34
  its(:as_json) do
35
35
  should == {
36
36
  'search_engine' => {
37
- :href => 'http://google.com',
38
- :title => 'Cool Search'
37
+ 'href' => 'http://google.com',
38
+ 'title' => 'Cool Search'
39
39
  }
40
40
  }
41
41
  end
@@ -121,9 +121,9 @@ module RoarExtensions
121
121
 
122
122
  it "has api _links" do
123
123
  subject['_links'].should == {
124
- 'self' => { :href => "/v1/products/9001" },
125
- 'related_products' => { :href => "/v1/products/9001/related" },
126
- 'category' => { :href => '/v1/categories/800'}
124
+ 'self' => { "href" => "/v1/products/9001" },
125
+ 'related_products' => { "href" => "/v1/products/9001/related" },
126
+ 'category' => { "href" => '/v1/categories/800'}
127
127
  }
128
128
  end
129
129
 
@@ -33,8 +33,8 @@ module RoarExtensions
33
33
  it "turns a hash with keys as rels into proper link representations" do
34
34
  subject.test_resource_link_json('self' => '/foo', 'next' => '/bar').
35
35
  should == {
36
- 'self' => { :href => '/foo' },
37
- 'next' => { :href => '/bar' }
36
+ 'self' => { 'href' => '/foo' },
37
+ 'next' => { 'href' => '/bar' }
38
38
  }
39
39
  end
40
40
  end
@@ -8,17 +8,20 @@ describe Roar::Representer::JSON::HAL do
8
8
  Module.new do
9
9
  include Roar::Representer::JSON
10
10
  include Roar::Representer::Feature::Hypermedia
11
- end
12
- end
13
11
 
14
- it "accepts strings for rel" do
15
- mod.class_eval do
16
12
  link :rel => 'self', :title => "Hey, @myabc" do
17
13
  "http://self"
18
14
  end
19
15
  end
16
+ end
17
+
18
+ it "accepts strings for rel" do
19
+ Object.new.extend(mod).to_hash['links'][0]['rel'].should == 'self'
20
+ end
20
21
 
21
- Object.new.extend(mod).to_hash['links'][0][:rel].should == 'self'
22
+ it "returns string keys" do
23
+ Object.new.extend(mod).to_hash['links'][0].keys.sort.
24
+ should == ['href', 'rel', 'title']
22
25
  end
23
26
  end
24
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roar-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-26 00:00:00.000000000 Z
13
+ date: 2012-09-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: roar
@@ -158,6 +158,7 @@ files:
158
158
  - lib/roar_extensions.rb
159
159
  - lib/roar_extensions/destroyed_record_presenter.rb
160
160
  - lib/roar_extensions/helpers/embedded_parameter_parsing.rb
161
+ - lib/roar_extensions/hypermedia_extensions.rb
161
162
  - lib/roar_extensions/json_hal_extensions.rb
162
163
  - lib/roar_extensions/link_presenter.rb
163
164
  - lib/roar_extensions/money_presenter.rb