yaks-html 0.6.0.alpha → 0.6.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -525
- data/Rakefile +1 -41
- data/{yaks-html/lib → lib}/yaks-html.rb +0 -0
- data/{yaks-html/lib → lib}/yaks/format/html.rb +0 -0
- data/{yaks-html/lib → lib}/yaks/format/template.html +0 -0
- data/{yaks-html/spec → spec}/spec_helper.rb +0 -0
- data/{yaks-html/yaks-html.gemspec → yaks-html.gemspec} +1 -1
- metadata +11 -108
- data/.gitignore +0 -7
- data/.travis.yml +0 -36
- data/ADDING_FORMATS.md +0 -13
- data/CHANGELOG.md +0 -149
- data/Gemfile +0 -4
- data/IDENTIFIERS.md +0 -113
- data/LICENSE +0 -7
- data/bench/bench.rb +0 -16
- data/bench/bench_1000.rb +0 -60
- data/notes.org +0 -72
- data/shaved_yak.gif +0 -0
- data/yaks-html/README.md +0 -3
- data/yaks/README.md +0 -526
- data/yaks/lib/yaks.rb +0 -62
- data/yaks/lib/yaks/breaking_changes.rb +0 -49
- data/yaks/lib/yaks/collection_mapper.rb +0 -52
- data/yaks/lib/yaks/collection_resource.rb +0 -73
- data/yaks/lib/yaks/config.rb +0 -65
- data/yaks/lib/yaks/config/dsl.rb +0 -165
- data/yaks/lib/yaks/default_policy.rb +0 -100
- data/yaks/lib/yaks/format.rb +0 -87
- data/yaks/lib/yaks/format/collection_json.rb +0 -42
- data/yaks/lib/yaks/format/hal.rb +0 -82
- data/yaks/lib/yaks/format/json_api.rb +0 -86
- data/yaks/lib/yaks/fp.rb +0 -26
- data/yaks/lib/yaks/fp/callable.rb +0 -9
- data/yaks/lib/yaks/fp/hash_updatable.rb +0 -19
- data/yaks/lib/yaks/fp/updatable.rb +0 -17
- data/yaks/lib/yaks/mapper.rb +0 -75
- data/yaks/lib/yaks/mapper/association.rb +0 -43
- data/yaks/lib/yaks/mapper/association_mapper.rb +0 -42
- data/yaks/lib/yaks/mapper/attribute.rb +0 -17
- data/yaks/lib/yaks/mapper/class_methods.rb +0 -37
- data/yaks/lib/yaks/mapper/config.rb +0 -44
- data/yaks/lib/yaks/mapper/has_many.rb +0 -29
- data/yaks/lib/yaks/mapper/has_one.rb +0 -15
- data/yaks/lib/yaks/mapper/link.rb +0 -91
- data/yaks/lib/yaks/null_resource.rb +0 -40
- data/yaks/lib/yaks/primitivize.rb +0 -45
- data/yaks/lib/yaks/resource.rb +0 -51
- data/yaks/lib/yaks/resource/link.rb +0 -21
- data/yaks/lib/yaks/runner.rb +0 -101
- data/yaks/lib/yaks/util.rb +0 -56
- data/yaks/lib/yaks/version.rb +0 -3
- data/yaks/spec/acceptance/acceptance_spec.rb +0 -48
- data/yaks/spec/acceptance/json_shared_examples.rb +0 -8
- data/yaks/spec/acceptance/models.rb +0 -48
- data/yaks/spec/fixture_helpers.rb +0 -14
- data/yaks/spec/integration/map_to_resource_spec.rb +0 -28
- data/yaks/spec/json/confucius.collection.json +0 -28
- data/yaks/spec/json/confucius.hal.json +0 -59
- data/yaks/spec/json/confucius.json_api.json +0 -51
- data/yaks/spec/json/john.hal.json +0 -29
- data/yaks/spec/json/plant_collection.collection.json +0 -32
- data/yaks/spec/json/plant_collection.hal.json +0 -34
- data/yaks/spec/json/youtypeitwepostit.collection.json +0 -45
- data/yaks/spec/spec_helper.rb +0 -30
- data/yaks/spec/support/classes_for_policy_testing.rb +0 -36
- data/yaks/spec/support/deep_eql.rb +0 -123
- data/yaks/spec/support/fixtures.rb +0 -6
- data/yaks/spec/support/friends_mapper.rb +0 -29
- data/yaks/spec/support/models.rb +0 -23
- data/yaks/spec/support/pet_mapper.rb +0 -3
- data/yaks/spec/support/pet_peeve_mapper.rb +0 -3
- data/yaks/spec/support/shared_contexts.rb +0 -57
- data/yaks/spec/support/youtypeit_models_mappers.rb +0 -20
- data/yaks/spec/unit/yaks/collection_mapper_spec.rb +0 -165
- data/yaks/spec/unit/yaks/collection_resource_spec.rb +0 -77
- data/yaks/spec/unit/yaks/config/dsl_spec.rb +0 -87
- data/yaks/spec/unit/yaks/config_spec.rb +0 -74
- data/yaks/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +0 -80
- data/yaks/spec/unit/yaks/default_policy_spec.rb +0 -70
- data/yaks/spec/unit/yaks/format/collection_json_spec.rb +0 -41
- data/yaks/spec/unit/yaks/format/hal_spec.rb +0 -44
- data/yaks/spec/unit/yaks/format/json_api_spec.rb +0 -42
- data/yaks/spec/unit/yaks/format_spec.rb +0 -37
- data/yaks/spec/unit/yaks/fp/callable_spec.rb +0 -13
- data/yaks/spec/unit/yaks/fp/hash_updatable_spec.rb +0 -22
- data/yaks/spec/unit/yaks/fp/updatable_spec.rb +0 -22
- data/yaks/spec/unit/yaks/fp_spec.rb +0 -31
- data/yaks/spec/unit/yaks/mapper/association_mapper_spec.rb +0 -60
- data/yaks/spec/unit/yaks/mapper/association_spec.rb +0 -135
- data/yaks/spec/unit/yaks/mapper/attribute_spec.rb +0 -20
- data/yaks/spec/unit/yaks/mapper/class_methods_spec.rb +0 -67
- data/yaks/spec/unit/yaks/mapper/config_spec.rb +0 -166
- data/yaks/spec/unit/yaks/mapper/has_many_spec.rb +0 -89
- data/yaks/spec/unit/yaks/mapper/has_one_spec.rb +0 -51
- data/yaks/spec/unit/yaks/mapper/link_spec.rb +0 -196
- data/yaks/spec/unit/yaks/mapper_spec.rb +0 -303
- data/yaks/spec/unit/yaks/null_resource_spec.rb +0 -32
- data/yaks/spec/unit/yaks/primitivize_spec.rb +0 -77
- data/yaks/spec/unit/yaks/resource/link_spec.rb +0 -20
- data/yaks/spec/unit/yaks/resource_spec.rb +0 -108
- data/yaks/spec/unit/yaks/runner_spec.rb +0 -260
- data/yaks/spec/unit/yaks/util_spec.rb +0 -49
- data/yaks/spec/yaml/confucius.yaml +0 -28
- data/yaks/spec/yaml/youtypeitwepostit.yaml +0 -9
- data/yaks/yaks.gemspec +0 -41
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Config do
|
4
|
-
include_context 'fixtures'
|
5
|
-
|
6
|
-
def self.configure(&blk)
|
7
|
-
subject(:config) { described_class.new(&blk) }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#initialize' do
|
11
|
-
context 'defaults' do
|
12
|
-
configure {}
|
13
|
-
|
14
|
-
its(:default_format) { should equal :hal }
|
15
|
-
its(:policy_class) { should < Yaks::DefaultPolicy }
|
16
|
-
its(:primitivize) { should be_a Yaks::Primitivize }
|
17
|
-
its(:serializers) { should eql({}) }
|
18
|
-
its(:hooks) { should eql([]) }
|
19
|
-
|
20
|
-
it 'should have empty format options' do
|
21
|
-
expect(config.format_options[:hal]).to eql({})
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'with a default format' do
|
26
|
-
configure do
|
27
|
-
default_format :json_api
|
28
|
-
end
|
29
|
-
|
30
|
-
its(:default_format) { should equal :json_api }
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'with a custom policy class' do
|
34
|
-
MyPolicy = Struct.new(:options)
|
35
|
-
configure do
|
36
|
-
policy MyPolicy
|
37
|
-
end
|
38
|
-
|
39
|
-
its(:policy_class) { should equal MyPolicy }
|
40
|
-
its(:policy) { should be_a MyPolicy }
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'with a rel template' do
|
44
|
-
configure do
|
45
|
-
rel_template 'http://rel/foo'
|
46
|
-
end
|
47
|
-
|
48
|
-
its(:policy_options) { should eql(rel_template: 'http://rel/foo') }
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'with format options' do
|
52
|
-
configure do
|
53
|
-
format_options :hal, plural_links: [:self, :profile]
|
54
|
-
end
|
55
|
-
|
56
|
-
specify do
|
57
|
-
expect(config.format_options[:hal]).to eql(plural_links: [:self, :profile])
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#call' do
|
63
|
-
configure do
|
64
|
-
rel_template 'http://api.mysuperfriends.com/{rel}'
|
65
|
-
format_options :hal, plural_links: [:copyright]
|
66
|
-
skip :serialize
|
67
|
-
end
|
68
|
-
|
69
|
-
specify do
|
70
|
-
expect(config.call(john)).to eql(load_json_fixture 'john.hal')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::DefaultPolicy, '#derive_mapper_from_object' do
|
4
|
-
subject(:policy) { described_class.new(options) }
|
5
|
-
|
6
|
-
let(:options) { {} }
|
7
|
-
|
8
|
-
context 'for a single instance' do
|
9
|
-
it 'should derive it by name' do
|
10
|
-
expect(policy.derive_mapper_from_object(Soy.new)).to be SoyMapper
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'given a namespace' do
|
14
|
-
let(:options) { {namespace: MyMappers} }
|
15
|
-
|
16
|
-
it 'should look inside the namespace' do
|
17
|
-
expect(policy.derive_mapper_from_object(Soy.new)).to be MyMappers::SoyMapper
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'for array-like objects' do
|
23
|
-
context 'given an empty array' do
|
24
|
-
it 'should return the vanilla CollectionMapper' do
|
25
|
-
expect(policy.derive_mapper_from_object([])).to be Yaks::CollectionMapper
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should find the mapper based on naming' do
|
30
|
-
expect(policy.derive_mapper_from_object([Soy.new])).to be SoyCollectionMapper
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'if no collection mapper with a similar name is defined' do
|
34
|
-
let(:options) { {namespace: Namespace} }
|
35
|
-
|
36
|
-
it 'should look for a CollectionMapper in the namespace' do
|
37
|
-
expect(policy.derive_mapper_from_object([Wheat.new])).to be(
|
38
|
-
Namespace::CollectionMapper
|
39
|
-
)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'for a model class inside a module' do
|
45
|
-
let(:options) { {namespace: Namespace} }
|
46
|
-
|
47
|
-
it 'should take the non-qualified classname, and search the mapper namespace with that' do
|
48
|
-
expect(policy.derive_mapper_from_object(Namespace::Nested::Rye.new)).to be(
|
49
|
-
Namespace::RyeMapper
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should take the non-qualified classname when looking for a collection mapper' do
|
54
|
-
expect(policy.derive_mapper_from_object([Namespace::Nested::Rye.new])).to be(
|
55
|
-
Namespace::RyeCollectionMapper
|
56
|
-
)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when trying to lookup CollectionMapper results in something other than an NameError' do
|
61
|
-
let(:options) { { namespace: DislikesCollectionMapper } }
|
62
|
-
|
63
|
-
it 'should propagate the error' do
|
64
|
-
expect {
|
65
|
-
policy.derive_mapper_from_object([])
|
66
|
-
}.to raise_error
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when trying to lookup a specific collection mapper results in something other than an NameError' do
|
71
|
-
let(:options) { { namespace: DislikesOtherMappers } }
|
72
|
-
|
73
|
-
it 'should propagate the error' do
|
74
|
-
expect {
|
75
|
-
policy.derive_mapper_from_object([Namespace::Nested::Rye.new])
|
76
|
-
}.to raise_error
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::DefaultPolicy do
|
4
|
-
subject(:policy) { described_class.new( options ) }
|
5
|
-
|
6
|
-
let(:options) { {} }
|
7
|
-
let(:association) { Yaks::Mapper::HasMany.new(name: 'shoes', collectionMapper: nil) }
|
8
|
-
|
9
|
-
describe '#initialize' do
|
10
|
-
it 'should work without arguments' do
|
11
|
-
expect(described_class.new.options).to eql described_class::DEFAULTS
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:options) { {foo: :bar} }
|
15
|
-
|
16
|
-
it 'should merge default and given options' do
|
17
|
-
expect(policy.options.values_at(:namespace, :foo)).to eql [Kernel, :bar]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#derive_type_from_mapper_class' do
|
22
|
-
specify do
|
23
|
-
expect(
|
24
|
-
policy.derive_type_from_mapper_class(Namespace::RyeMapper)
|
25
|
-
).to eql 'rye'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#derive_type_from_collection' do
|
30
|
-
specify do
|
31
|
-
expect(
|
32
|
-
policy.derive_type_from_collection([Soy.new])
|
33
|
-
).to eql 'soy'
|
34
|
-
end
|
35
|
-
|
36
|
-
specify do
|
37
|
-
expect(
|
38
|
-
policy.derive_type_from_collection([])
|
39
|
-
).to be_nil
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#derive_mapper_from_association' do
|
44
|
-
let(:options) { { namespace: Namespace } }
|
45
|
-
|
46
|
-
it 'should derive using the singular association name, and look inside the namespace' do
|
47
|
-
expect(policy.derive_mapper_from_association(association)).to be Namespace::ShoeMapper
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#derive_rel_from_association' do
|
52
|
-
it 'should expand the rel based on the association name' do
|
53
|
-
expect(policy.derive_rel_from_association(association)).to eql 'rel:shoes'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#expand_rel' do
|
58
|
-
let(:options) { { rel_template: 'http://foo/{?rel}' } }
|
59
|
-
it 'should expand the given template' do
|
60
|
-
expect(policy.expand_rel('rockets')).to eql 'http://foo/?rel=rockets'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#serializer_for_format' do
|
65
|
-
specify {
|
66
|
-
expect(policy.serializer_for_format(Yaks::Format::JsonAPI).call('foo' => [1,2])).to eql "{\n \"foo\": [\n 1,\n 2\n ]\n}"
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Format::CollectionJson do
|
4
|
-
context 'with the plant collection resource' do
|
5
|
-
include_context 'plant collection resource'
|
6
|
-
|
7
|
-
subject { Yaks::Primitivize.create.call(described_class.new.call(resource)) }
|
8
|
-
|
9
|
-
it { should deep_eql(load_json_fixture('plant_collection.collection')) }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'with a link without title' do
|
13
|
-
let(:resource) {
|
14
|
-
Yaks::Resource.new(
|
15
|
-
attributes: {foo: 'fooval', bar: 'barval'},
|
16
|
-
links: [Yaks::Resource::Link.new('the_rel', 'the_uri', {})]
|
17
|
-
)
|
18
|
-
}
|
19
|
-
|
20
|
-
subject {
|
21
|
-
Yaks::Primitivize.create.call(described_class.new.call(resource))
|
22
|
-
}
|
23
|
-
|
24
|
-
it 'should not render a name' do
|
25
|
-
should deep_eql(
|
26
|
-
"collection" => {
|
27
|
-
"version" => "1.0",
|
28
|
-
"items" => [
|
29
|
-
{
|
30
|
-
"data" => [
|
31
|
-
{ "name"=>"foo", "value"=>"fooval" },
|
32
|
-
{ "name"=>"bar", "value"=>"barval" }
|
33
|
-
],
|
34
|
-
"links" => [{"rel"=>"the_rel", "href"=>"the_uri"}]
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Format::Hal do
|
4
|
-
context 'with the plant collection resource' do
|
5
|
-
include_context 'plant collection resource'
|
6
|
-
|
7
|
-
subject { Yaks::Primitivize.create.call(described_class.new.call(resource)) }
|
8
|
-
|
9
|
-
it { should deep_eql(load_json_fixture('plant_collection.hal')) }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'with multiple links on the same rel' do
|
13
|
-
let(:format) {
|
14
|
-
described_class.new(:plural_links => 'my_plural_rel')
|
15
|
-
}
|
16
|
-
|
17
|
-
let(:resource) {
|
18
|
-
Yaks::Resource.new(
|
19
|
-
attributes: {foo: 'fooval', bar: 'barval'},
|
20
|
-
links: [
|
21
|
-
Yaks::Resource::Link.new('my_plural_rel', 'the_uri1', {}),
|
22
|
-
Yaks::Resource::Link.new('my_plural_rel', 'the_uri2', {})
|
23
|
-
]
|
24
|
-
)
|
25
|
-
}
|
26
|
-
|
27
|
-
subject {
|
28
|
-
Yaks::Primitivize.create.call(format.call(resource))
|
29
|
-
}
|
30
|
-
|
31
|
-
it 'should render both links' do
|
32
|
-
should deep_eql(
|
33
|
-
'foo' => 'fooval',
|
34
|
-
'bar' => 'barval',
|
35
|
-
'_links' => {
|
36
|
-
"my_plural_rel" => [
|
37
|
-
{"href"=>"the_uri1"},
|
38
|
-
{"href"=>"the_uri2"}
|
39
|
-
]
|
40
|
-
}
|
41
|
-
)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# Mainly tested through the acceptance tests, here covering a few specific edge cases
|
4
|
-
RSpec.describe Yaks::Format::JsonAPI do
|
5
|
-
let(:format) { Yaks::Format::JsonAPI.new }
|
6
|
-
|
7
|
-
context 'with no subresources' do
|
8
|
-
let(:resource) { Yaks::Resource.new(type: 'wizard', attributes: {foo: :bar}) }
|
9
|
-
|
10
|
-
it 'should not include a "linked" key' do
|
11
|
-
expect(format.call(resource)).to eql(
|
12
|
-
{'wizards' => [{foo: :bar}]}
|
13
|
-
)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with both a "href" attribute and a self link' do
|
18
|
-
let(:resource) {
|
19
|
-
Yaks::Resource.new(
|
20
|
-
type: 'wizard',
|
21
|
-
attributes: {
|
22
|
-
href: '/the/href'
|
23
|
-
},
|
24
|
-
links: [
|
25
|
-
Yaks::Resource::Link.new(:self, '/the/self/link', {})
|
26
|
-
]
|
27
|
-
)
|
28
|
-
}
|
29
|
-
|
30
|
-
it 'should give preference to the href attribute' do
|
31
|
-
expect(format.call(resource)).to eql(
|
32
|
-
{'wizards' => [
|
33
|
-
{
|
34
|
-
href: '/the/href'
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Format do
|
4
|
-
describe '.by_name' do
|
5
|
-
specify do
|
6
|
-
expect(Yaks::Format.by_name(:hal)).to eql Yaks::Format::Hal
|
7
|
-
end
|
8
|
-
specify do
|
9
|
-
expect(Yaks::Format.by_name(:json_api)).to eql Yaks::Format::JsonAPI
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '.by_mime_type' do
|
14
|
-
specify do
|
15
|
-
expect(Yaks::Format.by_mime_type('application/hal+json')).to eql Yaks::Format::Hal
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '.by_accept_header' do
|
20
|
-
specify do
|
21
|
-
expect(Yaks::Format.by_accept_header('application/hal+json;q=0.8, application/vnd.api+json')).to eql Yaks::Format::JsonAPI
|
22
|
-
end
|
23
|
-
specify do
|
24
|
-
expect(Yaks::Format.by_accept_header('application/hal+json;q=0.8, application/vnd.api+json;q=0.7')).to eql Yaks::Format::Hal
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '.mime_types' do
|
29
|
-
specify do
|
30
|
-
expect(Yaks::Format.mime_types).to eql(
|
31
|
-
collection_json: "application/vnd.collection+json",
|
32
|
-
hal: "application/hal+json",
|
33
|
-
json_api: "application/vnd.api+json"
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::FP::Callable do
|
4
|
-
it 'should delegate to_proc to method(:call)' do
|
5
|
-
obj = Class.new do
|
6
|
-
include Yaks::FP::Callable
|
7
|
-
|
8
|
-
def call(x) ; x * x ; end
|
9
|
-
end.new
|
10
|
-
|
11
|
-
expect([1,2,3].map(&obj)).to eql [1,4,9]
|
12
|
-
end
|
13
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe Yaks::FP::HashUpdatable do
|
5
|
-
let(:klz) do
|
6
|
-
Class.new do
|
7
|
-
include Equalizer.new(:aa, :bb, :cc)
|
8
|
-
include Yaks::FP::HashUpdatable.new(:aa, :bb, :cc)
|
9
|
-
|
10
|
-
attr_reader :aa, :bb, :cc
|
11
|
-
private :aa
|
12
|
-
|
13
|
-
def initialize(opts)
|
14
|
-
@aa, @bb, @cc = opts.values_at(:aa, :bb, :cc)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should only update the selected fields' do
|
20
|
-
expect(klz.new(aa: 1, bb: 2, cc: 3).update(bb: 7, cc: 9)).to eq klz.new(aa: 1, bb: 7, cc: 9)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe Yaks::FP::Updatable do
|
5
|
-
let(:klz) do
|
6
|
-
Class.new do
|
7
|
-
include Equalizer.new(:aa, :bb, :cc)
|
8
|
-
include Yaks::FP::Updatable.new(:aa, :bb, :cc)
|
9
|
-
|
10
|
-
attr_reader :aa, :bb, :cc
|
11
|
-
private :aa
|
12
|
-
|
13
|
-
def initialize(aa, bb, cc)
|
14
|
-
@aa, @bb, @cc = aa, bb, cc
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should only updated the selected fields' do
|
20
|
-
expect(klz.new(1,2,3).update(bb: 7, cc: 9)).to eq klz.new(1,7,9)
|
21
|
-
end
|
22
|
-
end
|