lhs 15.3.3 → 15.4.0.pre.hasone.1

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: e797056229bd637bef08633959ed8269af5e1ef7
4
- data.tar.gz: 77470b897ed36a4390117be48f81f5b622d32b42
3
+ metadata.gz: d100c6bf4ca9836392166b4aab5005e069f1bea8
4
+ data.tar.gz: f7175a8ae0a1a788a76613ed3f5005f09dfb5097
5
5
  SHA512:
6
- metadata.gz: 83b395627bb85c123c1001c74545d8004ecfae6e8718cd826fdf38890f1b160f88720c1c7a69882b9f3073a25c481e394582394a84e1acbf13e2c05c8ea53deb
7
- data.tar.gz: 788c795d9c435444485dd57beba6855be49211f02e1ae73f04db653a7b5a9a127ce86c6b4c878e95f7a10b2a6a926799f22de9db7850791d22f4637effcc0764
6
+ metadata.gz: 9a3dd07fea9af559e69dd527cc84d212c98a64dadfe6a840c3af4e3488563bc8da793baf542c6c5ed2d94a48125b3526462a55f99e249d7d3941d2de46a56f93
7
+ data.tar.gz: 17093f4ad5b922c5370cd5a37846b352288fcc73e2267fcdeb6b99416e1a10822e1078a56c3613db251b9df88d46ee0d6241a68c5f2072efc4ec1d08f3510b56
@@ -12,11 +12,18 @@ class LHS::Record
12
12
  end
13
13
 
14
14
  module ClassMethods
15
+
15
16
  def has_many(*options)
16
17
  name = options[0]
17
18
  options = options[1] || {}
18
19
  _relations[name] = { record_class_name: options.fetch(:class_name, name.to_s.singularize.classify) }
19
20
  end
21
+
22
+ def has_one(*options)
23
+ name = options[0]
24
+ options = options[1] || {}
25
+ _relations[name] = { record_class_name: options.fetch(:class_name, name.to_s.singularize.classify) }
26
+ end
20
27
  end
21
28
  end
22
29
  end
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '15.3.3'
2
+ VERSION = '15.4.0.pre.hasone.1'
3
3
  end
@@ -0,0 +1,68 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHS::Record do
4
+
5
+ let(:transaction) { Transaction.find(1) }
6
+ let(:user) { transaction.user }
7
+
8
+ before do
9
+ stub_request(:get, 'http://myservice/transactions/1')
10
+ .to_return(body: {
11
+ user: {
12
+ email_address: 'steve@local.ch'
13
+ }
14
+ }.to_json)
15
+ end
16
+
17
+ context 'has_one' do
18
+
19
+ before do
20
+ class Transaction < LHS::Record
21
+ endpoint 'http://myservice/transactions'
22
+ endpoint 'http://myservice/transactions/{id}'
23
+ has_one :user
24
+ end
25
+
26
+ class User < LHS::Record
27
+
28
+ def email
29
+ self[:email_address]
30
+ end
31
+ end
32
+ end
33
+
34
+ it 'casts the relation into the correct type' do
35
+ expect(user).to be_kind_of(User)
36
+ expect(user.email).to eq 'steve@local.ch'
37
+ end
38
+
39
+ it 'keeps hirachy when casting it to another class on access' do
40
+ expect(user._root._raw).to eq transaction._raw
41
+ expect(user.parent._raw).to eq transaction._raw
42
+ end
43
+ end
44
+
45
+ context 'custom class_name' do
46
+
47
+ before do
48
+ class Transaction < LHS::Record
49
+ endpoint 'http://myservice/transactions'
50
+ endpoint 'http://myservice/transactions/{id}'
51
+ has_one :user, class_name: 'Custom::User'
52
+ end
53
+
54
+ module Custom
55
+ class User < LHS::Record
56
+ def email
57
+ self[:email_address]
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ it 'casts the relation into the correct type' do
64
+ expect(user).to be_kind_of(Custom::User)
65
+ expect(user.email).to eq 'steve@local.ch'
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.3.3
4
+ version: 15.4.0.pre.hasone.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-14 00:00:00.000000000 Z
11
+ date: 2018-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -392,6 +392,7 @@ files:
392
392
  - spec/record/first_spec.rb
393
393
  - spec/record/handle_includes_errors_spec.rb
394
394
  - spec/record/has_many_spec.rb
395
+ - spec/record/has_one_spec.rb
395
396
  - spec/record/ignore_errors_spec.rb
396
397
  - spec/record/immutable_chains_spec.rb
397
398
  - spec/record/includes_all_spec.rb
@@ -447,9 +448,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
447
448
  version: 2.3.0
448
449
  required_rubygems_version: !ruby/object:Gem::Requirement
449
450
  requirements:
450
- - - ">="
451
+ - - ">"
451
452
  - !ruby/object:Gem::Version
452
- version: '0'
453
+ version: 1.3.1
453
454
  requirements:
454
455
  - Ruby >= 2.3.0
455
456
  rubyforge_project:
@@ -582,6 +583,7 @@ test_files:
582
583
  - spec/record/first_spec.rb
583
584
  - spec/record/handle_includes_errors_spec.rb
584
585
  - spec/record/has_many_spec.rb
586
+ - spec/record/has_one_spec.rb
585
587
  - spec/record/ignore_errors_spec.rb
586
588
  - spec/record/immutable_chains_spec.rb
587
589
  - spec/record/includes_all_spec.rb