massive_record 0.2.1 → 0.2.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +58 -2
- data/Gemfile.lock +17 -17
- data/README.md +98 -41
- data/lib/massive_record.rb +2 -1
- data/lib/massive_record/adapters/thrift/hbase/hbase.rb +2425 -2154
- data/lib/massive_record/adapters/thrift/hbase/hbase_constants.rb +3 -3
- data/lib/massive_record/adapters/thrift/hbase/hbase_types.rb +195 -195
- data/lib/massive_record/adapters/thrift/row.rb +35 -4
- data/lib/massive_record/adapters/thrift/table.rb +49 -12
- data/lib/massive_record/orm/attribute_methods.rb +77 -5
- data/lib/massive_record/orm/attribute_methods/cast_numbers_on_write.rb +24 -0
- data/lib/massive_record/orm/attribute_methods/dirty.rb +18 -0
- data/lib/massive_record/orm/attribute_methods/time_zone_conversion.rb +24 -3
- data/lib/massive_record/orm/attribute_methods/write.rb +8 -1
- data/lib/massive_record/orm/base.rb +62 -8
- data/lib/massive_record/orm/column.rb +7 -11
- data/lib/massive_record/orm/default_id.rb +1 -1
- data/lib/massive_record/orm/embedded.rb +66 -0
- data/lib/massive_record/orm/errors.rb +17 -0
- data/lib/massive_record/orm/finders.rb +124 -71
- data/lib/massive_record/orm/finders/rescue_missing_table_on_find.rb +1 -1
- data/lib/massive_record/orm/finders/scope.rb +58 -34
- data/lib/massive_record/orm/id_factory.rb +22 -105
- data/lib/massive_record/orm/id_factory/atomic_incrementation.rb +117 -0
- data/lib/massive_record/orm/id_factory/timestamp.rb +60 -0
- data/lib/massive_record/orm/identity_map.rb +256 -0
- data/lib/massive_record/orm/log_subscriber.rb +18 -0
- data/lib/massive_record/orm/observer.rb +69 -0
- data/lib/massive_record/orm/persistence.rb +47 -119
- data/lib/massive_record/orm/persistence/operations.rb +100 -0
- data/lib/massive_record/orm/persistence/operations/atomic_operation.rb +71 -0
- data/lib/massive_record/orm/persistence/operations/destroy.rb +17 -0
- data/lib/massive_record/orm/persistence/operations/embedded/destroy.rb +26 -0
- data/lib/massive_record/orm/persistence/operations/embedded/insert.rb +27 -0
- data/lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb +66 -0
- data/lib/massive_record/orm/persistence/operations/embedded/reload.rb +39 -0
- data/lib/massive_record/orm/persistence/operations/embedded/update.rb +29 -0
- data/lib/massive_record/orm/persistence/operations/insert.rb +19 -0
- data/lib/massive_record/orm/persistence/operations/reload.rb +26 -0
- data/lib/massive_record/orm/persistence/operations/suppress.rb +15 -0
- data/lib/massive_record/orm/persistence/operations/table_operation_helpers.rb +106 -0
- data/lib/massive_record/orm/persistence/operations/update.rb +25 -0
- data/lib/massive_record/orm/query_instrumentation.rb +26 -49
- data/lib/massive_record/orm/raw_data.rb +47 -0
- data/lib/massive_record/orm/relations.rb +4 -0
- data/lib/massive_record/orm/relations/interface.rb +134 -0
- data/lib/massive_record/orm/relations/metadata.rb +58 -12
- data/lib/massive_record/orm/relations/proxy.rb +17 -12
- data/lib/massive_record/orm/relations/proxy/embedded_in.rb +54 -0
- data/lib/massive_record/orm/relations/proxy/embedded_in_polymorphic.rb +15 -0
- data/lib/massive_record/orm/relations/proxy/embeds_many.rb +215 -0
- data/lib/massive_record/orm/relations/proxy/references_many.rb +112 -88
- data/lib/massive_record/orm/relations/proxy/references_one.rb +1 -1
- data/lib/massive_record/orm/relations/proxy/references_one_polymorphic.rb +1 -1
- data/lib/massive_record/orm/relations/proxy_collection.rb +84 -0
- data/lib/massive_record/orm/schema/column_family.rb +3 -2
- data/lib/massive_record/orm/schema/{column_interface.rb → embedded_interface.rb} +38 -4
- data/lib/massive_record/orm/schema/field.rb +2 -0
- data/lib/massive_record/orm/schema/table_interface.rb +19 -2
- data/lib/massive_record/orm/single_table_inheritance.rb +37 -2
- data/lib/massive_record/orm/timestamps.rb +17 -7
- data/lib/massive_record/orm/validations.rb +4 -0
- data/lib/massive_record/orm/validations/associated.rb +50 -0
- data/lib/massive_record/rails/railtie.rb +31 -0
- data/lib/massive_record/version.rb +1 -1
- data/lib/massive_record/wrapper/cell.rb +8 -1
- data/massive_record.gemspec +4 -4
- data/spec/adapter/thrift/atomic_increment_spec.rb +16 -0
- data/spec/adapter/thrift/table_find_spec.rb +14 -2
- data/spec/adapter/thrift/table_spec.rb +6 -6
- data/spec/adapter/thrift/utf8_encoding_of_id_spec.rb +71 -0
- data/spec/orm/cases/attribute_methods_spec.rb +215 -22
- data/spec/orm/cases/auto_generate_id_spec.rb +1 -1
- data/spec/orm/cases/change_id_spec.rb +62 -0
- data/spec/orm/cases/default_id_spec.rb +25 -6
- data/spec/orm/cases/default_values_spec.rb +6 -3
- data/spec/orm/cases/dirty_spec.rb +150 -102
- data/spec/orm/cases/embedded_spec.rb +250 -0
- data/spec/orm/cases/{finder_default_scope.rb → finder_default_scope_spec.rb} +4 -0
- data/spec/orm/cases/finder_scope_spec.rb +96 -29
- data/spec/orm/cases/finders_spec.rb +57 -10
- data/spec/orm/cases/id_factory/atomic_incrementation_spec.rb +72 -0
- data/spec/orm/cases/id_factory/timestamp_spec.rb +61 -0
- data/spec/orm/cases/identity_map/identity_map_spec.rb +357 -0
- data/spec/orm/cases/identity_map/middleware_spec.rb +74 -0
- data/spec/orm/cases/log_subscriber_spec.rb +15 -2
- data/spec/orm/cases/observing_spec.rb +61 -0
- data/spec/orm/cases/persistence_spec.rb +151 -60
- data/spec/orm/cases/raw_data_spec.rb +58 -0
- data/spec/orm/cases/single_table_inheritance_spec.rb +58 -2
- data/spec/orm/cases/table_spec.rb +3 -3
- data/spec/orm/cases/time_zone_awareness_spec.rb +27 -0
- data/spec/orm/cases/timestamps_spec.rb +23 -109
- data/spec/orm/cases/validation_spec.rb +9 -0
- data/spec/orm/models/address.rb +5 -1
- data/spec/orm/models/address_with_timestamp.rb +12 -0
- data/spec/orm/models/car.rb +5 -0
- data/spec/orm/models/person.rb +13 -1
- data/spec/orm/models/person_with_timestamp.rb +4 -2
- data/spec/orm/models/test_class.rb +1 -0
- data/spec/orm/persistence/operations/atomic_operation_spec.rb +58 -0
- data/spec/orm/persistence/operations/destroy_spec.rb +22 -0
- data/spec/orm/persistence/operations/embedded/destroy_spec.rb +71 -0
- data/spec/orm/persistence/operations/embedded/insert_spec.rb +59 -0
- data/spec/orm/persistence/operations/embedded/operation_helpers_spec.rb +92 -0
- data/spec/orm/persistence/operations/embedded/reload_spec.rb +67 -0
- data/spec/orm/persistence/operations/embedded/update_spec.rb +60 -0
- data/spec/orm/persistence/operations/insert_spec.rb +31 -0
- data/spec/orm/persistence/operations/reload_spec.rb +48 -0
- data/spec/orm/persistence/operations/suppress_spec.rb +17 -0
- data/spec/orm/persistence/operations/table_operation_helpers_spec.rb +98 -0
- data/spec/orm/persistence/operations/update_spec.rb +25 -0
- data/spec/orm/persistence/operations_spec.rb +58 -0
- data/spec/orm/relations/interface_spec.rb +188 -0
- data/spec/orm/relations/metadata_spec.rb +92 -15
- data/spec/orm/relations/proxy/embedded_in_polymorphic_spec.rb +37 -0
- data/spec/orm/relations/proxy/embedded_in_spec.rb +66 -0
- data/spec/orm/relations/proxy/embeds_many_spec.rb +651 -0
- data/spec/orm/relations/proxy/references_many_spec.rb +466 -2
- data/spec/orm/schema/column_family_spec.rb +21 -0
- data/spec/orm/schema/embedded_interface_spec.rb +181 -0
- data/spec/orm/schema/field_spec.rb +7 -0
- data/spec/orm/schema/table_interface_spec.rb +31 -1
- data/spec/shared/orm/id_factories.rb +44 -0
- data/spec/shared/orm/model_with_timestamps.rb +132 -0
- data/spec/shared/orm/persistence/a_persistence_embedded_operation_class.rb +3 -0
- data/spec/shared/orm/persistence/a_persistence_operation_class.rb +11 -0
- data/spec/shared/orm/persistence/a_persistence_table_operation_class.rb +11 -0
- data/spec/shared/orm/relations/proxy.rb +9 -2
- data/spec/spec_helper.rb +9 -0
- data/spec/support/mock_massive_record_connection.rb +2 -1
- metadata +106 -21
- data/spec/orm/cases/column_spec.rb +0 -49
- data/spec/orm/cases/id_factory_spec.rb +0 -92
- data/spec/orm/schema/column_interface_spec.rb +0 -136
@@ -45,7 +45,7 @@ describe "auto setting of ids" do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
MassiveRecord::ORM::IdFactory.should_receive(:next_for).with(Person).and_return(1)
|
48
|
+
MassiveRecord::ORM::IdFactory::AtomicIncrementation.should_receive(:next_for).with(Person).and_return(1)
|
49
49
|
@person.id.should == "1"
|
50
50
|
|
51
51
|
Person.class_eval { undef_method :default_id }
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MassiveRecord::ORM::Table do
|
4
|
+
include SetUpHbaseConnectionBeforeAll
|
5
|
+
include SetTableNamesToTestTable
|
6
|
+
|
7
|
+
let(:old_id) { "old_id" }
|
8
|
+
let(:new_id) { "new_id" }
|
9
|
+
|
10
|
+
subject do
|
11
|
+
Person.create!(old_id, {
|
12
|
+
:name => "Thorbjorn",
|
13
|
+
:age => 22,
|
14
|
+
:points => 1
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#change_id!" do
|
19
|
+
describe "successfully" do
|
20
|
+
before do
|
21
|
+
subject.change_id! new_id
|
22
|
+
end
|
23
|
+
|
24
|
+
its(:id) { should eq new_id }
|
25
|
+
|
26
|
+
it "saves itself with new id" do
|
27
|
+
Person.find(new_id).should eq subject
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has same attributes" do
|
31
|
+
Person.find(new_id).attributes.should eq subject.attributes
|
32
|
+
end
|
33
|
+
|
34
|
+
it "deletes the old id from the database" do
|
35
|
+
Person.should_not be_exists old_id
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "with identity map" do
|
39
|
+
it "works as expected" do
|
40
|
+
MassiveRecord::ORM::IdentityMap.use do
|
41
|
+
person = Person.create!("id", {:name => "Thorbjorn", :age => 22, :points => 1})
|
42
|
+
person.change_id! "id-2"
|
43
|
+
Person.find("id-2").should eq person
|
44
|
+
Person.should_not be_exists "id"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "unsuccessfully" do
|
51
|
+
it "raises error if unable to save new id" do
|
52
|
+
subject.should_receive(:save).and_return false
|
53
|
+
expect { subject.change_id! new_id }.to raise_error
|
54
|
+
end
|
55
|
+
|
56
|
+
it "raises error if unable to destroy old record" do
|
57
|
+
Person.any_instance.stub(:destroy).and_return false
|
58
|
+
expect { subject.change_id! new_id }.to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -8,31 +8,50 @@ describe ModelWithoutDefaultId do
|
|
8
8
|
|
9
9
|
context "with auto increment id" do
|
10
10
|
its(:id) { be_nil }
|
11
|
-
its(:
|
11
|
+
its(:set_id_from_factory_before_create) { be_true }
|
12
12
|
|
13
13
|
it "sets id to what next_id returns" do
|
14
|
-
|
14
|
+
MassiveRecord::ORM::IdFactory::AtomicIncrementation.should_receive(:next_for).and_return 1
|
15
15
|
subject.save
|
16
16
|
subject.id.should eq "1"
|
17
17
|
end
|
18
18
|
|
19
19
|
it "does nothing if the id is set before create" do
|
20
20
|
subject.id = 2
|
21
|
-
|
21
|
+
MassiveRecord::ORM::IdFactory::AtomicIncrementation.should_not_receive(:next_for)
|
22
22
|
subject.save
|
23
23
|
subject.id.should eq "2"
|
24
24
|
end
|
25
|
+
|
26
|
+
it "is configurable which factory to use" do
|
27
|
+
id_factory_was = ModelWithoutDefaultId.id_factory
|
28
|
+
ModelWithoutDefaultId.id_factory = MassiveRecord::ORM::IdFactory::Timestamp
|
29
|
+
|
30
|
+
MassiveRecord::ORM::IdFactory::Timestamp.should_receive(:next_for).and_return 123
|
31
|
+
subject.save
|
32
|
+
subject.id.should eq "123"
|
33
|
+
|
34
|
+
ModelWithoutDefaultId.id_factory = MassiveRecord::ORM::IdFactory::AtomicIncrementation
|
35
|
+
end
|
25
36
|
end
|
26
37
|
|
27
38
|
context "without auto increment id" do
|
28
|
-
before(:all) { subject.class.
|
29
|
-
after(:all) { subject.class.
|
39
|
+
before(:all) { subject.class.set_id_from_factory_before_create = false }
|
40
|
+
after(:all) { subject.class.set_id_from_factory_before_create = true }
|
30
41
|
|
31
42
|
its(:id) { be_nil }
|
32
|
-
its(:
|
43
|
+
its(:set_id_from_factory_before_create) { be_false }
|
33
44
|
|
34
45
|
it "raises error as expected when id is missing" do
|
35
46
|
expect { subject.save }.to raise_error MassiveRecord::ORM::IdMissing
|
36
47
|
end
|
37
48
|
end
|
49
|
+
|
50
|
+
it "is AtomicIncrementation on ORM::Table" do
|
51
|
+
Person.id_factory.instance.should be_instance_of MassiveRecord::ORM::IdFactory::AtomicIncrementation
|
52
|
+
end
|
53
|
+
|
54
|
+
it "is Timestamp on ORM::Embedded" do
|
55
|
+
Address.id_factory.instance.should be_instance_of MassiveRecord::ORM::IdFactory::Timestamp
|
56
|
+
end
|
38
57
|
end
|
@@ -13,25 +13,28 @@ describe "default values" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
context "new record" do
|
16
|
-
its(:
|
16
|
+
its(:dictionary) { should eq Hash.new }
|
17
17
|
its(:points) { should eq 1 }
|
18
18
|
its(:status) { should eq false }
|
19
|
+
its(:positive_as_default) { should eq true }
|
19
20
|
its(:phone_numbers) { should eq [] }
|
20
21
|
end
|
21
22
|
|
22
23
|
context "persisted record" do
|
23
24
|
before do
|
24
|
-
subject.
|
25
|
+
subject.dictionary = nil
|
25
26
|
subject.points = nil
|
26
27
|
subject.status = nil
|
28
|
+
subject.positive_as_default = false
|
27
29
|
subject.phone_numbers = nil
|
28
30
|
subject.save!
|
29
31
|
subject.reload
|
30
32
|
end
|
31
33
|
|
32
|
-
its(:
|
34
|
+
its(:dictionary) { should be_nil }
|
33
35
|
its(:points) { should be_nil }
|
34
36
|
its(:status) { should be_nil }
|
37
|
+
its(:positive_as_default) { should be_false }
|
35
38
|
its(:phone_numbers) { should eq [] }
|
36
39
|
end
|
37
40
|
end
|
@@ -3,126 +3,173 @@ require 'spec_helper'
|
|
3
3
|
describe "dirty" do
|
4
4
|
describe "dry run" do
|
5
5
|
include MockMassiveRecordConnection
|
6
|
+
include TimeZoneHelper
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it "should not be changed after created" do
|
12
|
-
@person.should_not be_changed
|
13
|
-
end
|
8
|
+
context "new record" do
|
9
|
+
subject { Person.new '1', :name => "Alice", :age => 20, :email => "foo@bar.com" }
|
10
|
+
let(:address) { Address.new("id1", :street => "foo") }
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
it "is not changed when first created" do
|
13
|
+
Person.new.should_not be_changed
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
16
|
+
it "initial values are changed" do
|
17
|
+
subject.should be_email_changed
|
18
|
+
end
|
24
19
|
|
25
|
-
it "should notice changes in boolean values from false to true" do
|
26
|
-
@person.status = !@person.status
|
27
|
-
@person.should be_status_changed
|
28
|
-
end
|
29
20
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
21
|
+
describe "changes in embedded relations" do
|
22
|
+
before { subject.addresses << address }
|
23
|
+
|
24
|
+
it "iterates over embedded relations and asks them if they have changes" do
|
25
|
+
should be_changed
|
26
|
+
end
|
27
|
+
|
28
|
+
it "includes addresses in changed" do
|
29
|
+
subject.changed.should include "addresses"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "includes knowledge of changes" do
|
33
|
+
address.street = address.street + "_NEW"
|
34
|
+
subject.name = subject.name + "_NEW"
|
35
|
+
subject.changes.should eq({
|
36
|
+
"name" => [nil, "Alice_NEW"],
|
37
|
+
"age" => [nil, 20],
|
38
|
+
"email" => [nil, "foo@bar.com"],
|
39
|
+
"addresses" => {
|
40
|
+
"id1" => {
|
41
|
+
"street" => [nil, "foo_NEW"]
|
42
|
+
}
|
43
|
+
}
|
44
|
+
})
|
45
|
+
end
|
46
|
+
end
|
35
47
|
end
|
36
48
|
|
37
|
-
|
38
|
-
|
39
|
-
@person.should_not be_age_changed
|
40
|
-
end
|
49
|
+
context "persisted" do
|
50
|
+
subject { Person.create '1', :name => "Alice", :age => 20, :email => "foo@bar.com" }
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
52
|
+
it "should not be changed if attribute is set to what it currently is" do
|
53
|
+
subject.name = "Alice"
|
54
|
+
should_not be_changed
|
55
|
+
end
|
47
56
|
|
57
|
+
it "should notice changes" do
|
58
|
+
subject.name = "Bob"
|
59
|
+
should be_changed
|
60
|
+
end
|
48
61
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@person.should_not be_changed
|
54
|
-
end
|
62
|
+
it "should notice changes in boolean values from false to true" do
|
63
|
+
subject.status = !subject.status
|
64
|
+
should be_status_changed
|
65
|
+
end
|
55
66
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
it "notices changes in time attributes" do
|
68
|
+
in_time_zone "utc" do
|
69
|
+
test = TestClass.new
|
70
|
+
test.tested_at = Time.now
|
71
|
+
test.should be_tested_at_changed
|
72
|
+
end
|
73
|
+
end
|
62
74
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
75
|
+
it "should notice changes in boolean values from true to false" do
|
76
|
+
subject.status = true
|
77
|
+
subject.save
|
78
|
+
subject.status = false
|
79
|
+
should be_status_changed
|
80
|
+
end
|
67
81
|
|
82
|
+
it "should not consider age set as string to the same as integer a change" do
|
83
|
+
subject.age = "20"
|
84
|
+
should_not be_age_changed
|
85
|
+
end
|
68
86
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@person.should_not be_changed
|
87
|
+
it "should not consider age set as string back to original value a change" do
|
88
|
+
subject.age = 30
|
89
|
+
subject.age = "20"
|
90
|
+
should_not be_age_changed
|
74
91
|
end
|
75
92
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
93
|
+
|
94
|
+
it "should know when a attribute is set to it's original value" do
|
95
|
+
original_name = subject.name
|
96
|
+
subject.name = "Bob"
|
97
|
+
subject.name = original_name
|
98
|
+
should_not be_changed
|
81
99
|
end
|
82
100
|
|
83
|
-
it "
|
84
|
-
|
85
|
-
|
86
|
-
|
101
|
+
it "should always keep the objects original value as _was" do
|
102
|
+
original_name = subject.name
|
103
|
+
subject.name = "Bob"
|
104
|
+
subject.name = "Foo"
|
105
|
+
subject.name_was.should == original_name
|
87
106
|
end
|
88
107
|
|
89
|
-
it "
|
90
|
-
|
91
|
-
|
92
|
-
@person.should_not be_changed
|
108
|
+
it "should return what name was" do
|
109
|
+
subject.name = "Bob"
|
110
|
+
subject.name_was.should == "Alice"
|
93
111
|
end
|
94
|
-
end
|
95
112
|
|
96
|
-
|
97
|
-
|
98
|
-
|
113
|
+
|
114
|
+
describe "should reset changes" do
|
115
|
+
it "on save" do
|
116
|
+
subject.name = "Bob"
|
117
|
+
subject.save
|
118
|
+
should_not be_changed
|
119
|
+
end
|
120
|
+
|
121
|
+
it "on save, but don't do it if save fails validation" do
|
122
|
+
subject.should_receive(:valid?).and_return(false)
|
123
|
+
subject.name = "Bob"
|
124
|
+
subject.save
|
125
|
+
should be_changed
|
126
|
+
end
|
127
|
+
|
128
|
+
it "on save!" do
|
129
|
+
subject.name = "Bob"
|
130
|
+
subject.save!
|
131
|
+
should_not be_changed
|
132
|
+
end
|
133
|
+
|
134
|
+
it "on reload" do
|
135
|
+
subject.name = "Bob"
|
136
|
+
subject.reload
|
137
|
+
should_not be_changed
|
138
|
+
end
|
99
139
|
end
|
100
140
|
|
101
|
-
|
102
|
-
|
103
|
-
|
141
|
+
describe "previous changes" do
|
142
|
+
it "should be blank before after reload" do
|
143
|
+
subject.reload
|
144
|
+
subject.previous_changes.should be_blank
|
145
|
+
end
|
104
146
|
|
105
|
-
|
147
|
+
it "should equal to changes before save" do
|
148
|
+
subject.name = "Bob"
|
149
|
+
changes_before_save = subject.changes
|
106
150
|
|
107
|
-
|
108
|
-
@person.previous_changes.should == changes_before_save
|
109
|
-
end
|
151
|
+
subject.save
|
110
152
|
|
111
|
-
|
112
|
-
|
113
|
-
|
153
|
+
subject.changes.should be_empty
|
154
|
+
subject.previous_changes.should == changes_before_save
|
155
|
+
end
|
114
156
|
|
115
|
-
|
157
|
+
it "should equal to changes before save!" do
|
158
|
+
subject.name = "Bob"
|
159
|
+
changes_before_save = subject.changes
|
116
160
|
|
117
|
-
|
118
|
-
|
119
|
-
|
161
|
+
subject.save!
|
162
|
+
|
163
|
+
subject.changes.should be_empty
|
164
|
+
subject.previous_changes.should == changes_before_save
|
165
|
+
end
|
120
166
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
167
|
+
it "should be nil after a reload" do
|
168
|
+
subject.name = "Bob"
|
169
|
+
subject.save
|
170
|
+
subject.reload
|
171
|
+
subject.previous_changes.should be_blank
|
172
|
+
end
|
126
173
|
end
|
127
174
|
end
|
128
175
|
end
|
@@ -132,22 +179,23 @@ describe "dirty" do
|
|
132
179
|
include SetUpHbaseConnectionBeforeAll
|
133
180
|
include SetTableNamesToTestTable
|
134
181
|
|
182
|
+
subject { Person.new }
|
183
|
+
|
135
184
|
before do
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
@person.status = "0"
|
185
|
+
subject.id = "test"
|
186
|
+
subject.points = "25"
|
187
|
+
subject.date_of_birth = "19850730"
|
188
|
+
subject.status = "0"
|
141
189
|
end
|
142
190
|
|
143
191
|
it "should update dirty status correctly after a reload" do
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
192
|
+
subject.dictionary = {:something => "strage"}
|
193
|
+
subject.save! :validate => false
|
194
|
+
subject.reload
|
195
|
+
subject.dictionary = {}
|
196
|
+
subject.save! :validate => false
|
197
|
+
subject.reload
|
198
|
+
subject.dictionary.should == {}
|
151
199
|
end
|
152
200
|
end
|
153
201
|
end
|