flatten_record 1.0.10 → 1.0.11

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.
@@ -57,13 +57,16 @@ describe FlattenRecord::Flattener do
57
57
  Denormalized
58
58
  end
59
59
 
60
- let(:order_with_customer_with_one_child) do
60
+ let(:customer) do
61
61
  child = Child.new(name: 'Ethan')
62
62
  child.cats << Cat.new(name: 'Meow')
63
63
 
64
- customer = Customer.create(name: 'Alvin')
65
- customer.children << child
66
-
64
+ c = Customer.create(name: 'Alvin')
65
+ c.children << child
66
+ c
67
+ end
68
+
69
+ let(:order_with_customer_with_one_child) do
67
70
  order = Order.new
68
71
  order.total = 100
69
72
 
@@ -99,8 +102,45 @@ describe FlattenRecord::Flattener do
99
102
  klass.destroy_with(order_with_customer_with_one_child)
100
103
  expect(klass.count).to eq(0)
101
104
  end
102
- end #/.find_with
103
105
 
106
+ it 'should be able to update related records, when only child is changed' do
107
+ order = order_with_customer_with_one_child
108
+ denormalized = klass.create_with(order)
109
+ expect(klass.count).to eq(1)
110
+
111
+ c = order.customer
112
+ c.update_attributes({name: "Anita"})
113
+
114
+ klass.destroy_with(c)
115
+ expect(klass.count).to eq(1)
116
+ expect(klass.first.customer_name).to eq("Anita")
117
+ end
118
+ end #/.destroy_with
119
+
120
+
121
+ context '.destroy_with_id' do
122
+ it 'should be able to destroy related records' do
123
+ order = order_with_customer_with_one_child
124
+ denormalized = klass.create_with(order)
125
+ expect(klass.count).to eq(1)
126
+
127
+ klass.destroy_with_id(order.id, order.class)
128
+ expect(klass.count).to eq(0)
129
+ end
130
+
131
+ it 'should be able to update related records, when only child is changed' do
132
+ order = order_with_customer_with_one_child
133
+ denormalized = klass.create_with(order)
134
+ expect(klass.count).to eq(1)
135
+
136
+ c = order.customer
137
+ c.update_attributes({name: "Anita"})
138
+
139
+ klass.destroy_with_id(c.id, c.class)
140
+ expect(klass.count).to eq(1)
141
+ expect(klass.first.customer_name).to eq("Anita")
142
+ end
143
+ end #/.destroy_with_id
104
144
 
105
145
  end
106
146
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flatten_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alvin S.J. Ng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails