rom-sql 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +12 -7
- data/CHANGELOG.md +28 -0
- data/Gemfile +6 -9
- data/README.md +5 -4
- data/circle.yml +10 -0
- data/lib/rom/plugins/relation/sql/auto_combine.rb +16 -3
- data/lib/rom/plugins/relation/sql/auto_wrap.rb +3 -2
- data/lib/rom/sql/association.rb +75 -0
- data/lib/rom/sql/association/many_to_many.rb +86 -0
- data/lib/rom/sql/association/many_to_one.rb +60 -0
- data/lib/rom/sql/association/name.rb +70 -0
- data/lib/rom/sql/association/one_to_many.rb +9 -0
- data/lib/rom/sql/association/one_to_one.rb +46 -0
- data/lib/rom/sql/association/one_to_one_through.rb +9 -0
- data/lib/rom/sql/commands.rb +2 -0
- data/lib/rom/sql/commands/create.rb +2 -2
- data/lib/rom/sql/commands/delete.rb +0 -1
- data/lib/rom/sql/commands/postgres.rb +76 -0
- data/lib/rom/sql/commands/update.rb +6 -3
- data/lib/rom/sql/commands_ext/postgres.rb +17 -0
- data/lib/rom/sql/gateway.rb +23 -15
- data/lib/rom/sql/header.rb +7 -1
- data/lib/rom/sql/plugin/assoc_macros.rb +3 -3
- data/lib/rom/sql/plugin/associates.rb +50 -9
- data/lib/rom/sql/qualified_attribute.rb +53 -0
- data/lib/rom/sql/relation.rb +76 -25
- data/lib/rom/sql/relation/reading.rb +138 -35
- data/lib/rom/sql/relation/writing.rb +21 -0
- data/lib/rom/sql/schema.rb +35 -0
- data/lib/rom/sql/schema/associations_dsl.rb +68 -0
- data/lib/rom/sql/schema/dsl.rb +27 -0
- data/lib/rom/sql/schema/inferrer.rb +80 -0
- data/lib/rom/sql/support/active_support_notifications.rb +27 -17
- data/lib/rom/sql/types.rb +11 -0
- data/lib/rom/sql/types/pg.rb +26 -0
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +4 -2
- data/spec/integration/association/many_to_many_spec.rb +137 -0
- data/spec/integration/association/many_to_one_spec.rb +110 -0
- data/spec/integration/association/one_to_many_spec.rb +58 -0
- data/spec/integration/association/one_to_one_spec.rb +57 -0
- data/spec/integration/association/one_to_one_through_spec.rb +90 -0
- data/spec/integration/combine_spec.rb +24 -24
- data/spec/integration/commands/create_spec.rb +215 -168
- data/spec/integration/commands/delete_spec.rb +88 -46
- data/spec/integration/commands/update_spec.rb +141 -60
- data/spec/integration/commands/upsert_spec.rb +83 -0
- data/spec/integration/gateway_spec.rb +9 -17
- data/spec/integration/migration_spec.rb +3 -5
- data/spec/integration/plugins/associates_spec.rb +168 -0
- data/spec/integration/plugins/auto_wrap_spec.rb +46 -0
- data/spec/integration/read_spec.rb +80 -77
- data/spec/integration/relation_schema_spec.rb +180 -0
- data/spec/integration/schema_inference_spec.rb +67 -0
- data/spec/integration/setup_spec.rb +22 -0
- data/spec/{support → integration/support}/active_support_notifications_spec.rb +0 -0
- data/spec/{support → integration/support}/rails_log_subscriber_spec.rb +0 -0
- data/spec/shared/database_setup.rb +46 -8
- data/spec/shared/relations.rb +8 -0
- data/spec/shared/users_and_accounts.rb +10 -0
- data/spec/shared/users_and_tasks.rb +20 -2
- data/spec/spec_helper.rb +64 -11
- data/spec/support/helpers.rb +9 -0
- data/spec/unit/association/many_to_many_spec.rb +89 -0
- data/spec/unit/association/many_to_one_spec.rb +81 -0
- data/spec/unit/association/name_spec.rb +68 -0
- data/spec/unit/association/one_to_many_spec.rb +62 -0
- data/spec/unit/association/one_to_one_spec.rb +62 -0
- data/spec/unit/association/one_to_one_through_spec.rb +69 -0
- data/spec/unit/association_errors_spec.rb +2 -4
- data/spec/unit/gateway_spec.rb +12 -3
- data/spec/unit/migration_tasks_spec.rb +3 -3
- data/spec/unit/migrator_spec.rb +2 -4
- data/spec/unit/{combined_associations_spec.rb → plugin/assoc_macros/combined_associations_spec.rb} +13 -19
- data/spec/unit/{many_to_many_spec.rb → plugin/assoc_macros/many_to_many_spec.rb} +9 -15
- data/spec/unit/{many_to_one_spec.rb → plugin/assoc_macros/many_to_one_spec.rb} +9 -14
- data/spec/unit/plugin/assoc_macros/one_to_many_spec.rb +78 -0
- data/spec/unit/plugin/base_view_spec.rb +11 -11
- data/spec/unit/plugin/pagination_spec.rb +62 -62
- data/spec/unit/relation_spec.rb +218 -146
- data/spec/unit/schema_spec.rb +15 -14
- data/spec/unit/types_spec.rb +40 -0
- metadata +105 -21
- data/.rubocop.yml +0 -74
- data/.rubocop_todo.yml +0 -21
- data/spec/unit/one_to_many_spec.rb +0 -83
@@ -1,11 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe 'Association errors' do
|
1
|
+
RSpec.describe 'Association errors' do
|
4
2
|
include_context 'users and tasks'
|
5
3
|
|
6
4
|
describe 'accessing an undefined association' do
|
7
5
|
specify do
|
8
|
-
|
6
|
+
conf.relation(:users) do
|
9
7
|
use :assoc_macros
|
10
8
|
|
11
9
|
def with_undefined
|
data/spec/unit/gateway_spec.rb
CHANGED
@@ -10,7 +10,16 @@ describe ROM::SQL::Gateway do
|
|
10
10
|
it_behaves_like 'a rom gateway' do
|
11
11
|
let(:identifier) { :sql }
|
12
12
|
let(:gateway) { ROM::SQL::Gateway }
|
13
|
-
let(:uri) {
|
13
|
+
let(:uri) { POSTGRES_DB_URI }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'sqlite with a file db' do
|
17
|
+
it 'establishes an sqlite connection' do
|
18
|
+
db_file = Tempfile.new('test.sqlite')
|
19
|
+
uri = "#{defined?(JRUBY_VERSION) ? 'jdbc:sqlite' : 'sqlite'}://#{db_file.path}"
|
20
|
+
gateway = ROM::SQL::Gateway.new(uri)
|
21
|
+
expect(gateway).to be_instance_of(ROM::SQL::Gateway)
|
22
|
+
end
|
14
23
|
end
|
15
24
|
|
16
25
|
describe '#dataset?' do
|
@@ -28,10 +37,10 @@ describe ROM::SQL::Gateway do
|
|
28
37
|
migrator = double('migrator')
|
29
38
|
|
30
39
|
expect(Sequel).to receive(:connect)
|
31
|
-
.with(
|
40
|
+
.with(POSTGRES_DB_URI, host: '127.0.0.1')
|
32
41
|
.and_return(conn)
|
33
42
|
|
34
|
-
gateway = ROM::SQL::Gateway.new(
|
43
|
+
gateway = ROM::SQL::Gateway.new(POSTGRES_DB_URI, migrator: migrator, host: '127.0.0.1')
|
35
44
|
|
36
45
|
expect(gateway.options).to eql(migrator: migrator)
|
37
46
|
end
|
@@ -7,12 +7,12 @@ namespace :db do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'MigrationTasks' do
|
10
|
-
let(:
|
11
|
-
let!(:container) { ROM.container(
|
10
|
+
let(:conf) { ROM::Configuration.new(:sql, POSTGRES_DB_URI) }
|
11
|
+
let!(:container) { ROM.container(conf) }
|
12
12
|
let(:migrator) { container.gateways[:default].migrator }
|
13
13
|
|
14
14
|
before do
|
15
|
-
ROM::SQL::RakeSupport.
|
15
|
+
allow(ROM::SQL::RakeSupport).to receive(:env) { conf }
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'db:reset' do
|
data/spec/unit/migrator_spec.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe ROM::SQL::Migration::Migrator do
|
1
|
+
RSpec.describe ROM::SQL::Migration::Migrator do
|
4
2
|
subject(:migrator) { ROM::SQL::Migration::Migrator.new(conn, options) }
|
5
3
|
|
6
|
-
let(:conn) { Sequel.connect(
|
4
|
+
let(:conn) { Sequel.connect(POSTGRES_DB_URI) }
|
7
5
|
let(:options) { { path: TMP_PATH.join('test/migrations') } }
|
8
6
|
|
9
7
|
describe '#create_file' do
|
data/spec/unit/{combined_associations_spec.rb → plugin/assoc_macros/combined_associations_spec.rb}
RENAMED
@@ -1,18 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe 'Defining multiple associations' do
|
1
|
+
RSpec.describe 'Defining multiple associations' do
|
4
2
|
include_context 'users and tasks'
|
5
3
|
|
6
|
-
before do
|
7
|
-
conn[:tasks].insert id: 2, user_id: 1, title: 'Go to sleep'
|
8
|
-
end
|
9
|
-
|
10
4
|
it 'extends relation with association methods' do
|
11
|
-
|
5
|
+
conf.relation(:users) { use :assoc_macros }
|
12
6
|
|
13
|
-
|
7
|
+
conf.relation(:tags) { use :assoc_macros }
|
14
8
|
|
15
|
-
|
9
|
+
conf.relation(:tasks) do
|
16
10
|
use :assoc_macros
|
17
11
|
|
18
12
|
many_to_one :users, key: :user_id
|
@@ -54,26 +48,26 @@ describe 'Defining multiple associations' do
|
|
54
48
|
tasks = container.relations.tasks
|
55
49
|
|
56
50
|
expect(tasks.with_user_and_tags.to_a).to eql([
|
57
|
-
{ id: 1, title: '
|
58
|
-
{ id: 2, title: '
|
51
|
+
{ id: 1, title: "Joe's task", name: 'Joe', tags_name: 'important' },
|
52
|
+
{ id: 2, title: "Jane's task", name: 'Jane', tags_name: nil }
|
59
53
|
])
|
60
54
|
|
61
55
|
expect(tasks.with_user_and_tags.sorted_by_tags_name.to_a).to eql([
|
62
|
-
{ id: 2, title: '
|
63
|
-
{ id: 1, title: '
|
56
|
+
{ id: 2, title: "Jane's task", name: 'Jane', tags_name: nil },
|
57
|
+
{ id: 1, title: "Joe's task", name: 'Joe', tags_name: 'important' }
|
64
58
|
])
|
65
59
|
|
66
60
|
expect(tasks.with_user_and_tags.by_tag('important').to_a).to eql([
|
67
|
-
{ id: 1, title: '
|
61
|
+
{ id: 1, title: "Joe's task", name: 'Joe', tags_name: 'important' }
|
68
62
|
])
|
69
63
|
|
70
64
|
expect(tasks.all.with_user.to_a).to eql([
|
71
|
-
{ id: 1, title: '
|
72
|
-
{ id: 2, title: '
|
65
|
+
{ id: 1, title: "Joe's task", name: 'Joe' },
|
66
|
+
{ id: 2, title: "Jane's task", name: 'Jane' }
|
73
67
|
])
|
74
68
|
|
75
|
-
expect(tasks.by_title('
|
76
|
-
[{ id: 2, user_id: 1, title: '
|
69
|
+
expect(tasks.by_title("Jane's task").to_a).to eql(
|
70
|
+
[{ id: 2, user_id: 1, title: "Jane's task" }]
|
77
71
|
)
|
78
72
|
end
|
79
73
|
end
|
@@ -1,17 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe 'Defining many-to-one association' do
|
1
|
+
RSpec.describe 'Defining many-to-one association' do
|
4
2
|
include_context 'users and tasks'
|
5
3
|
|
6
|
-
before do
|
7
|
-
conn[:tasks].insert id: 2, user_id: 1, title: 'Go to sleep'
|
8
|
-
end
|
9
|
-
|
10
4
|
it 'extends relation with association methods' do
|
11
|
-
|
12
|
-
|
5
|
+
conf.relation(:tags) { use :assoc_macros }
|
6
|
+
conf.relation(:task_tags) { use :assoc_macros }
|
13
7
|
|
14
|
-
|
8
|
+
conf.relation(:tasks) do
|
15
9
|
use :assoc_macros
|
16
10
|
|
17
11
|
many_to_many :tags,
|
@@ -41,17 +35,17 @@ describe 'Defining many-to-one association' do
|
|
41
35
|
tasks = container.relations.tasks
|
42
36
|
|
43
37
|
expect(tasks.all.with_tags.to_a).to eql([
|
44
|
-
{ id: 1, title: '
|
45
|
-
{ id: 2, title: '
|
38
|
+
{ id: 1, title: "Joe's task", name: 'important' },
|
39
|
+
{ id: 2, title: "Jane's task", name: nil }
|
46
40
|
])
|
47
41
|
|
48
42
|
expect(tasks.all.with_tags_and_tag_id.to_a).to eql([
|
49
|
-
{ id: 1, title: '
|
50
|
-
{ id: 2, title: '
|
43
|
+
{ id: 1, title: "Joe's task", tag_id: 1, name: 'important' },
|
44
|
+
{ id: 2, title: "Jane's task", tag_id: nil, name: nil }
|
51
45
|
])
|
52
46
|
|
53
47
|
expect(tasks.all.by_tag("important").to_a).to eql([
|
54
|
-
{ id: 1, title: '
|
48
|
+
{ id: 1, title: "Joe's task", name: 'important' }
|
55
49
|
])
|
56
50
|
|
57
51
|
expect(tasks.by_tag("not-here").to_a).to be_empty
|
@@ -1,20 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe 'Defining many-to-one association' do
|
1
|
+
RSpec.describe 'Defining many-to-one association' do
|
4
2
|
include_context 'users and tasks'
|
5
3
|
|
6
4
|
before do
|
7
|
-
|
8
|
-
conn[:tasks].insert id: 2, user_id: 2, title: 'Task one'
|
9
|
-
|
10
|
-
configuration.relation(:users) { use :assoc_macros }
|
5
|
+
conf.relation(:users) { use :assoc_macros }
|
11
6
|
end
|
12
7
|
|
13
8
|
it 'extends relation with association methods' do
|
14
|
-
|
9
|
+
conf.relation(:tasks) do
|
15
10
|
use :assoc_macros
|
16
11
|
|
17
|
-
many_to_one :users, key: :user_id, on: { name: '
|
12
|
+
many_to_one :users, key: :user_id, on: { name: 'Jane' }
|
18
13
|
|
19
14
|
def all
|
20
15
|
select(:id, :title)
|
@@ -25,7 +20,7 @@ describe 'Defining many-to-one association' do
|
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
28
|
-
|
23
|
+
conf.mappers do
|
29
24
|
define(:tasks)
|
30
25
|
|
31
26
|
define(:with_user, parent: :tasks) do
|
@@ -38,16 +33,16 @@ describe 'Defining many-to-one association' do
|
|
38
33
|
tasks = container.relations.tasks
|
39
34
|
|
40
35
|
expect(tasks.all.with_user.to_a).to eql(
|
41
|
-
[{ id:
|
36
|
+
[{ id: 2, name: 'Jane', title: "Jane's task" }]
|
42
37
|
)
|
43
38
|
|
44
39
|
expect(container.relation(:tasks).map_with(:with_user).all.with_user.to_a).to eql(
|
45
|
-
[{ id:
|
40
|
+
[{ id: 2, title: "Jane's task", user: { name: 'Jane' } }]
|
46
41
|
)
|
47
42
|
end
|
48
43
|
|
49
44
|
it "joins on specified key" do
|
50
|
-
|
45
|
+
conf.relation(:task_tags) do
|
51
46
|
use :assoc_macros
|
52
47
|
|
53
48
|
many_to_one :tags, key: :tag_id
|
@@ -57,7 +52,7 @@ describe 'Defining many-to-one association' do
|
|
57
52
|
end
|
58
53
|
end
|
59
54
|
|
60
|
-
|
55
|
+
conf.relation(:tags) { use :assoc_macros }
|
61
56
|
|
62
57
|
expect(container.relation(:task_tags).with_tags.to_a).to eq(
|
63
58
|
[{ tag_id: 1, task_id: 1, id: 1, name: "important" }]
|
@@ -0,0 +1,78 @@
|
|
1
|
+
RSpec.describe 'Defining one-to-many association' do
|
2
|
+
include_context 'users and tasks'
|
3
|
+
|
4
|
+
before do
|
5
|
+
conf.mappers do
|
6
|
+
define(:users)
|
7
|
+
|
8
|
+
define(:with_tasks, parent: :users) do
|
9
|
+
group tasks: [:tasks_id, :title]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
conf.relation(:tasks) { use :assoc_macros }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'extends relation with association methods' do
|
17
|
+
conf.relation(:users) do
|
18
|
+
use :assoc_macros
|
19
|
+
|
20
|
+
one_to_many :tasks, key: :user_id, on: { title: "Jane's task" }
|
21
|
+
|
22
|
+
def by_name(name)
|
23
|
+
where(name: name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def with_tasks
|
27
|
+
association_left_join(:tasks, select: [:id, :title])
|
28
|
+
end
|
29
|
+
|
30
|
+
def all
|
31
|
+
select(:id, :name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
users = container.relations.users
|
36
|
+
|
37
|
+
expect(users.with_tasks.by_name("Jane").to_a).to eql(
|
38
|
+
[{ id: 1, name: 'Jane', tasks_id: 2, title: "Jane's task" }]
|
39
|
+
)
|
40
|
+
|
41
|
+
result = container.relation(:users).map_with(:with_tasks)
|
42
|
+
.all.with_tasks.by_name("Jane").to_a
|
43
|
+
|
44
|
+
expect(result).to eql(
|
45
|
+
[{ id: 1, name: 'Jane', tasks: [{ tasks_id: 2, title: "Jane's task" }] }]
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'allows setting :conditions' do
|
50
|
+
conf.relation(:users) do
|
51
|
+
use :assoc_macros
|
52
|
+
|
53
|
+
one_to_many :janes_tasks, relation: :tasks, key: :user_id,
|
54
|
+
conditions: { name: 'Jane' }
|
55
|
+
|
56
|
+
def with_janes_tasks
|
57
|
+
association_left_join(:janes_tasks, select: [:id, :title])
|
58
|
+
end
|
59
|
+
|
60
|
+
def all
|
61
|
+
select(:id, :name)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
users = container.relations.users
|
66
|
+
|
67
|
+
expect(users.with_janes_tasks.to_a).to eql(
|
68
|
+
[{ id: 1, name: 'Jane', tasks_id: 2, title: "Jane's task" }]
|
69
|
+
)
|
70
|
+
|
71
|
+
result = container.relation(:users).map_with(:with_tasks)
|
72
|
+
.all.with_janes_tasks.to_a
|
73
|
+
|
74
|
+
expect(result).to eql(
|
75
|
+
[{ id: 1, name: 'Jane', tasks: [{ tasks_id: 2, title: "Jane's task" }] }]
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe 'Plugin / Base View' do
|
1
|
+
RSpec.describe 'Plugin / Base View' do
|
4
2
|
include_context 'database setup'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
with_adapters do
|
5
|
+
it 'defines base view' do
|
6
|
+
module Test
|
7
|
+
class Users < ROM::Relation[:sql]
|
8
|
+
dataset :users
|
9
|
+
register_as :users
|
10
|
+
end
|
11
11
|
end
|
12
|
-
end
|
13
12
|
|
14
|
-
|
13
|
+
conf.register_relation(Test::Users)
|
15
14
|
|
16
|
-
|
15
|
+
expect(container.relation(:users).base.header).to match_array([:id, :name])
|
16
|
+
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,91 +1,91 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
require 'rom/sql/plugin/pagination'
|
4
2
|
|
5
|
-
describe 'Plugin / Pagination' do
|
3
|
+
RSpec.describe 'Plugin / Pagination' do
|
6
4
|
include_context 'database setup'
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
with_adapters do
|
7
|
+
before do
|
8
|
+
9.times { |i| conn[:users].insert(name: "User #{i}") }
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
conf.relation(:users) do
|
11
|
+
use :pagination
|
13
12
|
|
14
|
-
|
13
|
+
per_page 4
|
14
|
+
end
|
15
15
|
end
|
16
|
-
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
describe '#page' do
|
18
|
+
it 'allow to call with stringify number' do
|
19
|
+
expect {
|
20
|
+
container.relation(:users).page('5')
|
21
|
+
}.to_not raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'preserves existing modifiers' do
|
25
|
+
expect(
|
26
|
+
container.relation(:users).send(:where, name: 'User 2').page(1).to_a.size
|
27
|
+
).to be(1)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
describe '#per_page' do
|
32
|
+
it 'allow to call with stringify number' do
|
33
|
+
expect {
|
34
|
+
container.relation(:users).per_page('5')
|
35
|
+
}.to_not raise_error
|
36
|
+
end
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
expect {
|
35
|
-
container.relation(:users).per_page('5')
|
36
|
-
}.to_not raise_error
|
37
|
-
end
|
38
|
+
it 'returns paginated relation with provided limit' do
|
39
|
+
users = container.relation(:users).page(2).per_page(5)
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
expect(users.dataset.opts[:offset]).to eql(5)
|
42
|
+
expect(users.dataset.opts[:limit]).to eql(5)
|
41
43
|
|
42
|
-
|
43
|
-
expect(users.dataset.opts[:limit]).to eql(5)
|
44
|
+
expect(users.pager.current_page).to eql(2)
|
44
45
|
|
45
|
-
|
46
|
+
expect(users.pager.total).to be(9)
|
47
|
+
expect(users.pager.total_pages).to be(2)
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
expect(users.pager.prev_page).to be(1)
|
52
|
-
expect(users.pager.limit_value).to eql(5)
|
49
|
+
expect(users.pager.next_page).to be(nil)
|
50
|
+
expect(users.pager.prev_page).to be(1)
|
51
|
+
expect(users.pager.limit_value).to eql(5)
|
52
|
+
end
|
53
53
|
end
|
54
|
-
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
describe '#total_pages' do
|
56
|
+
it 'returns a single page when elements are a perfect fit' do
|
57
|
+
users = container.relation(:users).page(1).per_page(3)
|
58
|
+
expect(users.pager.total_pages).to eql(3)
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
it 'returns the exact number of pages to accommodate all elements' do
|
62
|
+
users = container.relation(:users).per_page(9)
|
63
|
+
expect(users.pager.total_pages).to eql(1)
|
64
|
+
end
|
65
65
|
end
|
66
|
-
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
describe '#pager' do
|
68
|
+
it 'returns a pager with pagination meta-info' do
|
69
|
+
users = container.relation(:users).page(1)
|
71
70
|
|
72
|
-
|
73
|
-
|
71
|
+
expect(users.pager.total).to be(9)
|
72
|
+
expect(users.pager.total_pages).to be(3)
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
expect(users.pager.current_page).to be(1)
|
75
|
+
expect(users.pager.next_page).to be(2)
|
76
|
+
expect(users.pager.prev_page).to be(nil)
|
78
77
|
|
79
|
-
|
78
|
+
users = container.relation(:users).page(2)
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
expect(users.pager.current_page).to be(2)
|
81
|
+
expect(users.pager.next_page).to be(3)
|
82
|
+
expect(users.pager.prev_page).to be(1)
|
84
83
|
|
85
|
-
|
84
|
+
users = container.relation(:users).page(3)
|
86
85
|
|
87
|
-
|
88
|
-
|
86
|
+
expect(users.pager.next_page).to be(nil)
|
87
|
+
expect(users.pager.prev_page).to be(2)
|
88
|
+
end
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|