upholsterer 0.4.4 → 0.4.5
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.rdoc +4 -0
- data/lib/upholsterer/json_presenter.rb +4 -5
- data/lib/upholsterer/version.rb +1 -1
- data/spec/base_spec.rb +3 -3
- data/spec/support/matchers/json_matcher.rb +18 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82a5b679c3a25d0c7e689e13c81cd3694610d4d8
|
4
|
+
data.tar.gz: 5ede3e5c7b04cd34376d21becbe2de1326c57295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c84077f3ad3c5c0694c485755b88007d8820d9ce35a34540c29f2d2499715c031ce6f605f2cce25d6642a54b995c77c030a6c4f07a264c2253dd088cc314aee
|
7
|
+
data.tar.gz: 3194d7453a8173575df38ff6e90c4f19e2f7b289d0d9d564f99dc8c1c861b290de394b6b392216f0a83e206a0410f971a1cdce40f2f148e52151c2bf0365b3c6
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Based on SimplePresenter (https://github.com/fnando/simple_presenter)
|
4
4
|
|
5
|
+
{<img src="https://codeclimate.com/github/Archistart/upholsterer/badges/gpa.svg" />}[https://codeclimate.com/github/Archistart/upholsterer]
|
6
|
+
{<img src="https://hakiri.io/github/Archistart/upholsterer/master.svg" alt="security" />}[https://hakiri.io/github/Archistart/upholsterer/master]
|
7
|
+
{<img src="https://travis-ci.org/Archistart/upholsterer.svg" />}[https://travis-ci.org/Archistart/upholsterer]
|
8
|
+
|
5
9
|
== Installation
|
6
10
|
|
7
11
|
gem install upholsterer
|
@@ -1,17 +1,16 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
|
+
|
1
3
|
module Upholsterer
|
2
4
|
class Base
|
5
|
+
delegate :to_json, :as_json, to: :to_hash, prefix: false
|
6
|
+
|
3
7
|
def to_hash
|
4
8
|
Hash[json_fields.collect do |field|
|
5
9
|
[field, public_send(field)]
|
6
10
|
end]
|
7
11
|
end
|
8
12
|
|
9
|
-
def to_json(*args)
|
10
|
-
to_hash
|
11
|
-
end
|
12
|
-
|
13
13
|
alias :to_h :to_hash
|
14
|
-
alias :as_json :to_json
|
15
14
|
|
16
15
|
private
|
17
16
|
|
data/lib/upholsterer/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -183,7 +183,7 @@ describe Upholsterer::Base do
|
|
183
183
|
let(:comment) { double body: 'Some comment', user: 'user' }
|
184
184
|
subject { ExposeAllPresenter.new(comment).to_json }
|
185
185
|
|
186
|
-
it { should eq '' }
|
186
|
+
it { should eq '{}' }
|
187
187
|
end
|
188
188
|
|
189
189
|
describe 'expose with block' do
|
@@ -198,7 +198,7 @@ describe Upholsterer::Base do
|
|
198
198
|
its(:email) { should eq 'foo@bar.com' }
|
199
199
|
its(:type) { should eq 'test_type' }
|
200
200
|
its(:description) { should eq 'test_description' }
|
201
|
-
its(:to_json) { should
|
201
|
+
its(:to_json) { should be_json_with(name: 'Test', email: 'foo@bar.com', id: 1, description: 'test_description', type: 'test_type') }
|
202
202
|
end
|
203
203
|
|
204
204
|
context 'Real presenter' do
|
@@ -208,7 +208,7 @@ describe Upholsterer::Base do
|
|
208
208
|
its(:email) { should eq 'foo@bar.com' }
|
209
209
|
its(:type) { should eq 'real_type' }
|
210
210
|
its(:description) { should eq 'real_description' }
|
211
|
-
its(:to_json) { should
|
211
|
+
its(:to_json) { should be_json_with(name: 'Real', email: 'foo@bar.com', id: 1, description: 'real_description', type: 'real_type') }
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec::Matchers.define :be_json_with do |expected|
|
2
|
+
match do |json_string|
|
3
|
+
json_string == expected.to_json
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec::Matchers.define :contain_keys do |*expected|
|
8
|
+
match do |json_string|
|
9
|
+
begin
|
10
|
+
@actual = JSON.parse(json_string).keys
|
11
|
+
@expected = expected.first
|
12
|
+
@actual.sort == @expected.sort
|
13
|
+
rescue
|
14
|
+
@actual = []
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upholsterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-12-
|
13
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- spec/support/comment_presenter.rb
|
99
99
|
- spec/support/expose_all_presenter.rb
|
100
100
|
- spec/support/iterator_presenter.rb
|
101
|
+
- spec/support/matchers/json_matcher.rb
|
101
102
|
- spec/support/user.rb
|
102
103
|
- spec/support/user_presenter.rb
|
103
104
|
- spec/upholsterer_spec.rb
|