cot 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97cc9be92f280e8658df89c21a99f4696a051cf2
4
- data.tar.gz: 072105df4b9c734f20e1834193a37f76fad112e9
3
+ metadata.gz: 8718cf838c838590a4c3c8fa565d136d3de861b9
4
+ data.tar.gz: 875186e08f60fe759f77ddeab1b0f50aa6ba3a25
5
5
  SHA512:
6
- metadata.gz: 68a07d3af871d1793999cdafd4cab1ee7c1134ee78d917f85976dade39e77189f4b67d28c75090d0c14abe255f5a714984254426af2ff08dd4241bcc3f5805b9
7
- data.tar.gz: a568ee0327301c1cfaf2adcb5352ffd89ff51f264f02ad2aa440c2bf8a75d13f5eca3a34625cf8032ed486d1a9955bcda27544bdd803b796df7dd83185d5fb8c
6
+ metadata.gz: e08b26c691f494eaff718912b694c13fd92a850bf928f3f67ede2510cbc5a16b63522c6e06318ad8f3ff256a439b25639cb92b73016348287b79697b992083d4
7
+ data.tar.gz: bd6f6bdcda4fd1499b936fe93c79fcdde2e8353cebcafa8872f21bb3e3956fb325f7fa74560e1314187b7d9eddf03e37192ccd411c4e38fd08dffc544a96a148
@@ -0,0 +1,3 @@
1
+ SimpleCov.start 'rails' do
2
+ add_filter 'spec'
3
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cot (0.1.1)
4
+ cot (0.1.2)
5
5
  activemodel
6
6
 
7
7
  GEM
@@ -19,9 +19,11 @@ GEM
19
19
  ast (2.0.0)
20
20
  builder (3.2.2)
21
21
  diff-lcs (1.2.5)
22
+ docile (1.1.5)
22
23
  i18n (0.6.11)
23
24
  json (1.8.1)
24
25
  minitest (5.4.0)
26
+ multi_json (1.10.1)
25
27
  parser (2.2.0.pre.3)
26
28
  ast (>= 1.1, < 3.0)
27
29
  slop (~> 3.4, >= 3.4.5)
@@ -55,6 +57,11 @@ GEM
55
57
  shoulda-context (1.2.1)
56
58
  shoulda-matchers (2.6.1)
57
59
  activesupport (>= 3.0.0)
60
+ simplecov (0.9.0)
61
+ docile (~> 1.1.0)
62
+ multi_json
63
+ simplecov-html (~> 0.8.0)
64
+ simplecov-html (0.8.0)
58
65
  slop (3.5.0)
59
66
  thread_safe (0.3.4)
60
67
  tzinfo (1.2.1)
@@ -70,3 +77,4 @@ DEPENDENCIES
70
77
  rspec-its
71
78
  rubocop
72
79
  shoulda
80
+ simplecov
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'rspec', '>= 0'
24
24
  s.add_development_dependency 'rspec-its', '>= 0'
25
25
  s.add_development_dependency 'rubocop', '>= 0'
26
+ s.add_development_dependency 'simplecov', '>= 0'
26
27
  end
@@ -80,9 +80,15 @@ module Cot
80
80
  serializable_hash.to_json
81
81
  end
82
82
 
83
- def serializable_hash
83
+ def serializable_hash(options = {})
84
84
  attrs = {}
85
- defined_properties.each do |m|
85
+ properties_list = defined_properties
86
+ if options[:only]
87
+ properties_list &= Array(options[:only]).map(&:to_sym)
88
+ elsif options[:except]
89
+ properties_list -= Array(options[:except]).map(&:to_sym)
90
+ end
91
+ properties_list.each do |m|
86
92
  attrs[inverted_properties_mapping.fetch(m, m)] = self[m]
87
93
  end
88
94
  attrs
@@ -1,3 +1,3 @@
1
1
  module Cot
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -10,14 +10,44 @@ describe Cot::Frame do
10
10
  end
11
11
  subject { @foo }
12
12
  its(:to_json) { should be_kind_of String }
13
- its(:serializable_hash) { should be_kind_of Hash }
14
- it 'has two keys' do
15
- expect(subject.serializable_hash.size).to eq 2
16
- end
17
13
  it 'needs more serialziable tests'
18
14
  its(:id) { should eq 5 }
19
15
  its(:foo) { should eq 'this will be foo' }
20
16
 
17
+ context 'serializable_hash' do
18
+ its(:serializable_hash) { should be_kind_of Hash }
19
+ it 'has two keys' do
20
+ expect(subject.serializable_hash.size).to eq 2
21
+ end
22
+
23
+ it 'should accept an option hash' do
24
+ expect do
25
+ subject.serializable_hash(only: :foo)
26
+ end.to_not raise_error
27
+ end
28
+
29
+ context 'only option' do
30
+ it 'should return properties specified' do
31
+ expect(subject.serializable_hash(only: :foo).size).to eq 1
32
+ expect(subject.serializable_hash(only: :foo)[:bar]).to eq 'this will be foo'
33
+ expect(subject.serializable_hash(only: [:foo, :id]).size).to eq 2
34
+ expect(subject.serializable_hash(only: 'foo').size).to eq 1
35
+ expect(subject.serializable_hash(only: 'foo')[:bar]).to eq 'this will be foo'
36
+ expect(subject.serializable_hash(only: :blah).size).to eq 0
37
+ end
38
+ end
39
+
40
+ context 'except option' do
41
+ it 'should not return properties specified' do
42
+ expect(subject.serializable_hash(except: :foo).size).to eq 1
43
+ expect(subject.serializable_hash(except: :foo)[:id]).to eq 5
44
+ expect(subject.serializable_hash(except: [:foo, :id]).size).to eq 0
45
+ expect(subject.serializable_hash(except: 'foo').size).to eq 1
46
+ expect(subject.serializable_hash(except: 'foo')[:id]).to eq 5
47
+ end
48
+ end
49
+ end
50
+
21
51
  context 'exists?' do
22
52
  it 'is true if id is present' do
23
53
  expect(@foo.exists?).to be_truthy
@@ -1,3 +1,5 @@
1
+ require 'simplecov'
2
+
1
3
  ENV['RAILS_ENV'] ||= 'test'
2
4
 
3
5
  require 'cot'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Henrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Simplifies creating models for rest based resources
98
112
  email:
99
113
  - crimsonknave@gmail.com
@@ -105,6 +119,7 @@ files:
105
119
  - .rubocop.yml
106
120
  - .ruby-gemset
107
121
  - .ruby-version
122
+ - .simplecov
108
123
  - Gemfile
109
124
  - Gemfile.lock
110
125
  - LICENSE
@@ -136,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
151
  version: '0'
137
152
  requirements: []
138
153
  rubyforge_project:
139
- rubygems_version: 2.1.9
154
+ rubygems_version: 2.1.10
140
155
  signing_key:
141
156
  specification_version: 4
142
157
  summary: Simplifies creating models for rest based resources