rom 0.2.0 → 0.3.0
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.
- checksums.yaml +7 -0
- data/.gitignore +3 -3
- data/.ruby-version +1 -1
- data/.travis.yml +13 -14
- data/{Changelog.md → CHANGELOG.md} +12 -3
- data/Gemfile +14 -10
- data/Gemfile.devtools +16 -16
- data/Guardfile +2 -5
- data/README.md +68 -56
- data/Rakefile +3 -3
- data/config/flay.yml +2 -2
- data/config/mutant.yml +2 -4
- data/config/rubocop.yml +30 -0
- data/lib/rom.rb +47 -9
- data/lib/rom/adapter.rb +52 -0
- data/lib/rom/adapter/memory.rb +70 -0
- data/lib/rom/boot.rb +158 -0
- data/lib/rom/boot/base_relation_dsl.rb +43 -0
- data/lib/rom/boot/dsl.rb +30 -0
- data/lib/rom/boot/mapper_dsl.rb +23 -0
- data/lib/rom/boot/relation_dsl.rb +23 -0
- data/lib/rom/boot/schema_dsl.rb +27 -0
- data/lib/rom/env.rb +48 -0
- data/lib/rom/header.rb +123 -0
- data/lib/rom/mapper.rb +38 -153
- data/lib/rom/mapper_builder.rb +85 -0
- data/lib/rom/model_builder.rb +58 -0
- data/lib/rom/ra.rb +196 -0
- data/lib/rom/ra/operation/group.rb +49 -0
- data/lib/rom/ra/operation/join.rb +41 -0
- data/lib/rom/ra/operation/wrap.rb +45 -0
- data/lib/rom/reader.rb +62 -0
- data/lib/rom/reader_builder.rb +28 -0
- data/lib/rom/relation.rb +41 -350
- data/lib/rom/relation_builder.rb +48 -0
- data/lib/rom/repository.rb +28 -53
- data/lib/rom/support/registry.rb +34 -0
- data/lib/rom/version.rb +3 -0
- data/rom.gemspec +12 -10
- data/spec/integration/adapters/extending_relations_spec.rb +43 -0
- data/spec/integration/mappers/definition_dsl_spec.rb +82 -0
- data/spec/integration/mappers/prefixing_attributes_spec.rb +42 -0
- data/spec/integration/mappers/renaming_attributes_spec.rb +138 -0
- data/spec/integration/ra/group_spec.rb +47 -0
- data/spec/integration/ra/join_spec.rb +24 -0
- data/spec/integration/ra/wrap_spec.rb +37 -0
- data/spec/integration/relations/reading_spec.rb +116 -0
- data/spec/integration/relations/registry_dsl_spec.rb +44 -0
- data/spec/integration/schema_spec.rb +29 -0
- data/spec/integration/setup_spec.rb +18 -0
- data/spec/shared/users_and_tasks.rb +34 -0
- data/spec/spec_helper.rb +14 -36
- data/spec/unit/rom/adapter_spec.rb +59 -0
- data/spec/unit/rom/header_spec.rb +58 -0
- data/spec/unit/rom/mapper_spec.rb +27 -0
- data/spec/unit/rom/ra/operation/group_spec.rb +55 -0
- data/spec/unit/rom/ra/operation/wrap_spec.rb +29 -0
- data/spec/unit/rom/relation_spec.rb +34 -0
- metadata +122 -190
- data/lib/rom/constants.rb +0 -16
- data/lib/rom/environment.rb +0 -105
- data/lib/rom/environment/builder.rb +0 -71
- data/lib/rom/mapper/attribute.rb +0 -108
- data/lib/rom/mapper/builder.rb +0 -58
- data/lib/rom/mapper/builder/definition.rb +0 -162
- data/lib/rom/mapper/header.rb +0 -103
- data/lib/rom/mapper/loader_builder.rb +0 -26
- data/lib/rom/schema.rb +0 -21
- data/lib/rom/schema/builder.rb +0 -59
- data/lib/rom/schema/definition.rb +0 -84
- data/lib/rom/schema/definition/relation.rb +0 -80
- data/lib/rom/schema/definition/relation/base.rb +0 -27
- data/lib/rom/session.rb +0 -111
- data/lib/rom/session/environment.rb +0 -67
- data/lib/rom/session/identity_map.rb +0 -43
- data/lib/rom/session/mapper.rb +0 -62
- data/lib/rom/session/relation.rb +0 -140
- data/lib/rom/session/state.rb +0 -59
- data/lib/rom/session/state/created.rb +0 -22
- data/lib/rom/session/state/deleted.rb +0 -25
- data/lib/rom/session/state/persisted.rb +0 -34
- data/lib/rom/session/state/transient.rb +0 -20
- data/lib/rom/session/state/updated.rb +0 -29
- data/lib/rom/session/tracker.rb +0 -62
- data/lib/rom/support/axiom/adapter.rb +0 -111
- data/lib/rom/support/axiom/adapter/data_objects.rb +0 -38
- data/lib/rom/support/axiom/adapter/memory.rb +0 -25
- data/lib/rom/support/axiom/adapter/postgres.rb +0 -19
- data/lib/rom/support/axiom/adapter/sqlite3.rb +0 -20
- data/lib/version.rb +0 -3
- data/spec/integration/environment_setup_spec.rb +0 -24
- data/spec/integration/grouped_mappers_spec.rb +0 -87
- data/spec/integration/join_and_group_spec.rb +0 -76
- data/spec/integration/join_and_wrap_spec.rb +0 -68
- data/spec/integration/mapping_embedded_relations_spec.rb +0 -73
- data/spec/integration/mapping_relations_spec.rb +0 -120
- data/spec/integration/schema_definition_spec.rb +0 -152
- data/spec/integration/session_spec.rb +0 -87
- data/spec/integration/wrapped_mappers_spec.rb +0 -73
- data/spec/shared/unit/environment_context.rb +0 -6
- data/spec/shared/unit/loader.rb +0 -11
- data/spec/shared/unit/loader_identity.rb +0 -13
- data/spec/shared/unit/mapper_context.rb +0 -11
- data/spec/shared/unit/relation_context.rb +0 -82
- data/spec/shared/unit/session_environment_context.rb +0 -11
- data/spec/shared/unit/session_relation_context.rb +0 -18
- data/spec/support/helper.rb +0 -34
- data/spec/support/ice_nine_config.rb +0 -10
- data/spec/support/test_mapper.rb +0 -110
- data/spec/unit/rom/environment/builder/mapping_spec.rb +0 -24
- data/spec/unit/rom/environment/builder/schema_spec.rb +0 -33
- data/spec/unit/rom/environment/class_methods/setup_spec.rb +0 -18
- data/spec/unit/rom/environment/repository_spec.rb +0 -21
- data/spec/unit/rom/mapper/attribute/embedded_collection/to_ast_spec.rb +0 -18
- data/spec/unit/rom/mapper/attribute/embedded_value/to_ast_spec.rb +0 -16
- data/spec/unit/rom/mapper/attribute/rename_spec.rb +0 -9
- data/spec/unit/rom/mapper/attribute/to_ast_spec.rb +0 -9
- data/spec/unit/rom/mapper/builder/class_methods/call_spec.rb +0 -61
- data/spec/unit/rom/mapper/class_methods/build_spec.rb +0 -55
- data/spec/unit/rom/mapper/dump_spec.rb +0 -11
- data/spec/unit/rom/mapper/group_spec.rb +0 -35
- data/spec/unit/rom/mapper/header/each_spec.rb +0 -26
- data/spec/unit/rom/mapper/header/element_reader_spec.rb +0 -21
- data/spec/unit/rom/mapper/header/group_spec.rb +0 -18
- data/spec/unit/rom/mapper/header/join_spec.rb +0 -14
- data/spec/unit/rom/mapper/header/keys_spec.rb +0 -29
- data/spec/unit/rom/mapper/header/project_spec.rb +0 -13
- data/spec/unit/rom/mapper/header/rename_spec.rb +0 -11
- data/spec/unit/rom/mapper/header/to_ast_spec.rb +0 -11
- data/spec/unit/rom/mapper/header/wrap_spec.rb +0 -18
- data/spec/unit/rom/mapper/identity_from_tuple_spec.rb +0 -11
- data/spec/unit/rom/mapper/identity_spec.rb +0 -11
- data/spec/unit/rom/mapper/join_spec.rb +0 -15
- data/spec/unit/rom/mapper/load_spec.rb +0 -11
- data/spec/unit/rom/mapper/new_object_spec.rb +0 -14
- data/spec/unit/rom/mapper/project_spec.rb +0 -11
- data/spec/unit/rom/mapper/rename_spec.rb +0 -16
- data/spec/unit/rom/mapper/wrap_spec.rb +0 -35
- data/spec/unit/rom/relation/delete_spec.rb +0 -15
- data/spec/unit/rom/relation/drop_spec.rb +0 -11
- data/spec/unit/rom/relation/each_spec.rb +0 -23
- data/spec/unit/rom/relation/first_spec.rb +0 -19
- data/spec/unit/rom/relation/group_spec.rb +0 -29
- data/spec/unit/rom/relation/inject_mapper_spec.rb +0 -17
- data/spec/unit/rom/relation/insert_spec.rb +0 -13
- data/spec/unit/rom/relation/last_spec.rb +0 -19
- data/spec/unit/rom/relation/one_spec.rb +0 -49
- data/spec/unit/rom/relation/rename_spec.rb +0 -21
- data/spec/unit/rom/relation/replace_spec.rb +0 -13
- data/spec/unit/rom/relation/restrict_spec.rb +0 -25
- data/spec/unit/rom/relation/sort_by_spec.rb +0 -25
- data/spec/unit/rom/relation/take_spec.rb +0 -11
- data/spec/unit/rom/relation/to_a_spec.rb +0 -20
- data/spec/unit/rom/relation/update_spec.rb +0 -25
- data/spec/unit/rom/relation/wrap_spec.rb +0 -29
- data/spec/unit/rom/repository/class_methods/build_spec.rb +0 -27
- data/spec/unit/rom/repository/element_reader_spec.rb +0 -21
- data/spec/unit/rom/repository/element_writer_spec.rb +0 -18
- data/spec/unit/rom/schema/builder/class_methods/build_spec.rb +0 -103
- data/spec/unit/rom/schema/element_reader_spec.rb +0 -15
- data/spec/unit/rom/session/class_methods/start_spec.rb +0 -23
- data/spec/unit/rom/session/clean_predicate_spec.rb +0 -21
- data/spec/unit/rom/session/environment/element_reader_spec.rb +0 -13
- data/spec/unit/rom/session/flush_spec.rb +0 -58
- data/spec/unit/rom/session/mapper/load_spec.rb +0 -47
- data/spec/unit/rom/session/relation/delete_spec.rb +0 -28
- data/spec/unit/rom/session/relation/dirty_predicate_spec.rb +0 -35
- data/spec/unit/rom/session/relation/identity_spec.rb +0 -11
- data/spec/unit/rom/session/relation/new_spec.rb +0 -50
- data/spec/unit/rom/session/relation/save_spec.rb +0 -50
- data/spec/unit/rom/session/relation/state_spec.rb +0 -23
- data/spec/unit/rom/session/relation/track_spec.rb +0 -23
- data/spec/unit/rom/session/relation/tracking_predicate_spec.rb +0 -23
- data/spec/unit/rom/session/relation/update_attributes_spec.rb +0 -45
- data/spec/unit/rom/session/state_spec.rb +0 -79
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Relation, '#restrict' do
|
6
|
-
include_context 'Relation'
|
7
|
-
|
8
|
-
share_examples_for 'restricted relation' do
|
9
|
-
specify do
|
10
|
-
should eq([jane])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'with condition hash' do
|
15
|
-
subject { relation.restrict(name: 'Jane').to_a }
|
16
|
-
|
17
|
-
it_behaves_like 'restricted relation'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with a block' do
|
21
|
-
subject { relation.restrict { |r| r.name.eq('Jane') }.to_a }
|
22
|
-
|
23
|
-
it_behaves_like 'restricted relation'
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Relation, '#sort_by' do
|
6
|
-
include_context 'Relation'
|
7
|
-
|
8
|
-
share_examples_for 'sorted relation' do
|
9
|
-
specify do
|
10
|
-
should eql([jack, jade, jane, john])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'with a list of attribute names' do
|
15
|
-
subject { relation.sort_by([:name]).to_a }
|
16
|
-
|
17
|
-
it_behaves_like 'sorted relation'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with a block' do
|
21
|
-
subject { relation.sort_by { |r| [r.name] }.to_a }
|
22
|
-
|
23
|
-
it_behaves_like 'sorted relation'
|
24
|
-
end
|
25
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Relation, '#to_a' do
|
6
|
-
subject(:relation) { described_class.new(axiom_relation, mapper) }
|
7
|
-
|
8
|
-
let(:axiom_relation) { [1, 2] }
|
9
|
-
let(:loaded_objects) { %w(1 2) }
|
10
|
-
fake(:mapper)
|
11
|
-
|
12
|
-
before do
|
13
|
-
stub(mapper).load(1) { '1' }
|
14
|
-
stub(mapper).load(2) { '2' }
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'gets all tuples and loads them via mapper' do
|
18
|
-
expect(relation.to_a).to eql(loaded_objects)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Relation, '#update' do
|
6
|
-
include_context 'Relation'
|
7
|
-
|
8
|
-
subject { relation.update(john, old_tuple) }
|
9
|
-
|
10
|
-
let!(:old_tuple) { relation.mapper.dump(john) }
|
11
|
-
|
12
|
-
it { should be_instance_of(Relation) }
|
13
|
-
|
14
|
-
before do
|
15
|
-
john.name = 'John Doe'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'replaces old object with the new one' do
|
19
|
-
expect(subject.restrict(name: 'John Doe').one).to eq(john)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'removes old object' do
|
23
|
-
expect(subject.restrict(name: 'John').count).to be(0)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Relation, '#wrap' do
|
6
|
-
let(:users) { Relation.new(user_relation, user_mapper) }
|
7
|
-
let(:tasks) { Relation.new(task_relation, task_mapper) }
|
8
|
-
|
9
|
-
fake(:user_relation) { Axiom::Relation }
|
10
|
-
fake(:user_mapper) { Mapper }
|
11
|
-
|
12
|
-
fake(:task_relation) { Axiom::Relation }
|
13
|
-
fake(:task_header) { Axiom::Relation::Header }
|
14
|
-
fake(:task_mapper) { Mapper }
|
15
|
-
|
16
|
-
fake(:wrapped_relation) { Axiom::Relation }
|
17
|
-
fake(:wrapped_mapper) { Mapper }
|
18
|
-
|
19
|
-
it "wraps relation and mapper" do
|
20
|
-
stub(task_relation).header { task_header }
|
21
|
-
stub(user_relation).wrap(:tasks => task_header) { wrapped_relation }
|
22
|
-
stub(user_mapper).wrap(:tasks => task_mapper) { wrapped_mapper }
|
23
|
-
|
24
|
-
expect(users.wrap(:tasks => tasks)).to eql(Relation.new(wrapped_relation, wrapped_mapper))
|
25
|
-
|
26
|
-
expect(user_relation).to have_received.wrap(:tasks => task_header)
|
27
|
-
expect(user_mapper).to have_received.wrap(:tasks => task_mapper)
|
28
|
-
end
|
29
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Repository, '.build' do
|
6
|
-
subject { described_class.build(name, uri) }
|
7
|
-
|
8
|
-
let(:name) { :test }
|
9
|
-
|
10
|
-
context 'with a registered uri scheme' do
|
11
|
-
let(:uri) { Addressable::URI.parse('memory://test') }
|
12
|
-
|
13
|
-
it { should be_instance_of(described_class) }
|
14
|
-
|
15
|
-
its(:name) { should be(name) }
|
16
|
-
its(:adapter) { should eq(Axiom::Adapter.build(uri)) }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with an unregistered uri scheme' do
|
20
|
-
let(:uri) { Addressable::URI.parse('unregistered://test') }
|
21
|
-
let(:msg) { "#{uri.scheme.inspect} is no registered uri scheme" }
|
22
|
-
|
23
|
-
specify do
|
24
|
-
expect { subject }.to raise_error(Axiom::UnknownAdapterError, msg)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Repository, '#[]' do
|
6
|
-
subject { object[relation_name] }
|
7
|
-
|
8
|
-
let(:object) { described_class.build(name, uri) }
|
9
|
-
let(:name) { :bigdata }
|
10
|
-
let(:uri) { Addressable::URI.parse('memory://test') }
|
11
|
-
|
12
|
-
let(:relation) { Axiom::Relation::Base.new(relation_name, header) }
|
13
|
-
let(:relation_name) { :test }
|
14
|
-
let(:header) { [] }
|
15
|
-
|
16
|
-
before do
|
17
|
-
object[relation_name] = relation
|
18
|
-
end
|
19
|
-
|
20
|
-
it { should eq(relation) }
|
21
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Repository, '#[]=' do
|
6
|
-
subject { object[:users] }
|
7
|
-
|
8
|
-
before do
|
9
|
-
object[:users] = relation
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:object) { Repository.build(:test, Addressable::URI.parse('memory://test')) }
|
13
|
-
let(:relation) { Axiom::Relation::Base.new(:users, []) }
|
14
|
-
|
15
|
-
it { should eq(relation) }
|
16
|
-
|
17
|
-
it { should be_instance_of(Axiom::Relation::Variable::Materialized) }
|
18
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Schema::Builder, '.build' do
|
6
|
-
include_context 'Environment'
|
7
|
-
|
8
|
-
let(:registry) { Hash[test: repository] }
|
9
|
-
|
10
|
-
let(:keys) { [:id] }
|
11
|
-
|
12
|
-
let(:schema) {
|
13
|
-
key_args = keys
|
14
|
-
|
15
|
-
described_class.build(registry) do
|
16
|
-
base_relation :users do
|
17
|
-
repository :test
|
18
|
-
|
19
|
-
attribute :id, Integer
|
20
|
-
attribute :name, String
|
21
|
-
|
22
|
-
key(*key_args)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
}
|
26
|
-
|
27
|
-
let(:header) {
|
28
|
-
Axiom::Relation::Header.coerce([[:id, Integer], [:name, String]], keys: keys)
|
29
|
-
}
|
30
|
-
|
31
|
-
let(:relation) {
|
32
|
-
Axiom::Relation::Base.new(:users, header)
|
33
|
-
}
|
34
|
-
|
35
|
-
fake(:repository)
|
36
|
-
fake(:gateway) { Axiom::Relation }
|
37
|
-
|
38
|
-
before do
|
39
|
-
stub(repository).[]=(:users, relation) { gateway }
|
40
|
-
stub(repository).[](:users) { gateway }
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.it_registers_relation
|
44
|
-
it 'registers base relation in the repository' do
|
45
|
-
expect(subject[:users]).to be(gateway)
|
46
|
-
expect(repository).to have_received.[]=(:users, relation)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'defining base relations' do
|
51
|
-
subject { schema }
|
52
|
-
|
53
|
-
context 'with a single key' do
|
54
|
-
it_registers_relation
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'with multiple keys' do
|
58
|
-
let(:keys) { [:id, :name] }
|
59
|
-
|
60
|
-
it_registers_relation
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'defining relations' do
|
65
|
-
subject do
|
66
|
-
schema.call do
|
67
|
-
relation :restricted_users do
|
68
|
-
users.restrict(name: 'Jane')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'registers restricted relation' do
|
74
|
-
stub(gateway).restrict(name: 'Jane') { gateway }
|
75
|
-
|
76
|
-
expect(subject[:restricted_users]).to be(gateway)
|
77
|
-
|
78
|
-
expect(gateway).to have_received.restrict(name: 'Jane')
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when invalid relation name is used' do
|
82
|
-
subject do
|
83
|
-
schema.call do
|
84
|
-
relation :restricted_users do
|
85
|
-
not_here.restrict
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'raises error' do
|
91
|
-
expect { subject }.to raise_error(
|
92
|
-
NameError, /method `not_here'/
|
93
|
-
)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'without block' do
|
99
|
-
subject { Schema::Builder.build({}) }
|
100
|
-
|
101
|
-
it { should be_instance_of(Schema::Builder) }
|
102
|
-
end
|
103
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Schema, "#[]" do
|
4
|
-
subject(:schema) { Schema.new(users: relation) }
|
5
|
-
|
6
|
-
fake(:relation)
|
7
|
-
|
8
|
-
it "returns registered relation" do
|
9
|
-
expect(schema[:users]).to be(relation)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "raises error when relation is missing" do
|
13
|
-
expect { schema[:not_here] }.to raise_error
|
14
|
-
end
|
15
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Session, '.start' do
|
6
|
-
include_context 'Session::Relation'
|
7
|
-
|
8
|
-
let(:user) { model.new(id: 3, name: 'Piotr') }
|
9
|
-
|
10
|
-
it 'starts a new session' do
|
11
|
-
Session.start(users: relation) do |session|
|
12
|
-
expect(session).to be_clean
|
13
|
-
expect(session).to be_instance_of(Session)
|
14
|
-
expect(session[:users]).to be_instance_of(Session::Relation)
|
15
|
-
|
16
|
-
session[:users].track(user).save(user)
|
17
|
-
|
18
|
-
session.flush
|
19
|
-
end
|
20
|
-
|
21
|
-
expect(relation.to_a).to include(user)
|
22
|
-
end
|
23
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Session, '#clean?' do
|
6
|
-
subject { session.clean? }
|
7
|
-
|
8
|
-
include_context 'Session::Relation'
|
9
|
-
|
10
|
-
context 'when tracker has no pending state changes' do
|
11
|
-
it { should be_true }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when tracker has pending state changes' do
|
15
|
-
before do
|
16
|
-
session[:users].delete(user)
|
17
|
-
end
|
18
|
-
|
19
|
-
it { should be_false }
|
20
|
-
end
|
21
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Session::Environment, '#[]' do
|
6
|
-
subject { object[:users] }
|
7
|
-
|
8
|
-
include_context 'Session::Environment'
|
9
|
-
|
10
|
-
it 'returns session relation proxy' do
|
11
|
-
expect(subject).to be_kind_of(Session::Relation)
|
12
|
-
end
|
13
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Session, '#flush' do
|
6
|
-
subject { session.flush }
|
7
|
-
|
8
|
-
include_context 'Session::Relation'
|
9
|
-
|
10
|
-
let(:object) { session }
|
11
|
-
|
12
|
-
let(:john) { session[:users].to_a.first }
|
13
|
-
let(:jane) { session[:users].to_a.last }
|
14
|
-
let(:piotr) { session[:users].new(id: 3, name: 'Piotr') }
|
15
|
-
|
16
|
-
before do
|
17
|
-
session[:users].delete(john)
|
18
|
-
|
19
|
-
jane.name = 'Jane Doe'
|
20
|
-
session[:users].save(jane)
|
21
|
-
|
22
|
-
session[:users].save(piotr)
|
23
|
-
end
|
24
|
-
|
25
|
-
it_behaves_like 'a command method'
|
26
|
-
|
27
|
-
it { should be_clean }
|
28
|
-
|
29
|
-
it 'commits all deletes' do
|
30
|
-
expect(subject[:users].to_a).to_not include(john)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'commits all updates' do
|
34
|
-
expect(subject[:users].to_a.first).to eq(relation.to_a.first)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'commits all inserts' do
|
38
|
-
expect(subject[:users].to_a).to include(piotr)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'sets correct state for created objects' do
|
42
|
-
expect(subject[:users].state(piotr)).to be_persisted
|
43
|
-
expect(subject[:users].dirty?(piotr)).to be(false)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'registers newly created object in the IM' do
|
47
|
-
expect(subject[:users].restrict { |r| r.name.eq('Piotr') }.to_a.first).to be(piotr)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'sets correct state for updated objects' do
|
51
|
-
expect(subject[:users].state(jane)).to be_persisted
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'sets correct state for deleted objects' do
|
55
|
-
expect(subject[:users].state(john)).to be_frozen
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|