rom-sql 0.7.0 → 0.8.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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +12 -7
  4. data/CHANGELOG.md +28 -0
  5. data/Gemfile +6 -9
  6. data/README.md +5 -4
  7. data/circle.yml +10 -0
  8. data/lib/rom/plugins/relation/sql/auto_combine.rb +16 -3
  9. data/lib/rom/plugins/relation/sql/auto_wrap.rb +3 -2
  10. data/lib/rom/sql/association.rb +75 -0
  11. data/lib/rom/sql/association/many_to_many.rb +86 -0
  12. data/lib/rom/sql/association/many_to_one.rb +60 -0
  13. data/lib/rom/sql/association/name.rb +70 -0
  14. data/lib/rom/sql/association/one_to_many.rb +9 -0
  15. data/lib/rom/sql/association/one_to_one.rb +46 -0
  16. data/lib/rom/sql/association/one_to_one_through.rb +9 -0
  17. data/lib/rom/sql/commands.rb +2 -0
  18. data/lib/rom/sql/commands/create.rb +2 -2
  19. data/lib/rom/sql/commands/delete.rb +0 -1
  20. data/lib/rom/sql/commands/postgres.rb +76 -0
  21. data/lib/rom/sql/commands/update.rb +6 -3
  22. data/lib/rom/sql/commands_ext/postgres.rb +17 -0
  23. data/lib/rom/sql/gateway.rb +23 -15
  24. data/lib/rom/sql/header.rb +7 -1
  25. data/lib/rom/sql/plugin/assoc_macros.rb +3 -3
  26. data/lib/rom/sql/plugin/associates.rb +50 -9
  27. data/lib/rom/sql/qualified_attribute.rb +53 -0
  28. data/lib/rom/sql/relation.rb +76 -25
  29. data/lib/rom/sql/relation/reading.rb +138 -35
  30. data/lib/rom/sql/relation/writing.rb +21 -0
  31. data/lib/rom/sql/schema.rb +35 -0
  32. data/lib/rom/sql/schema/associations_dsl.rb +68 -0
  33. data/lib/rom/sql/schema/dsl.rb +27 -0
  34. data/lib/rom/sql/schema/inferrer.rb +80 -0
  35. data/lib/rom/sql/support/active_support_notifications.rb +27 -17
  36. data/lib/rom/sql/types.rb +11 -0
  37. data/lib/rom/sql/types/pg.rb +26 -0
  38. data/lib/rom/sql/version.rb +1 -1
  39. data/rom-sql.gemspec +4 -2
  40. data/spec/integration/association/many_to_many_spec.rb +137 -0
  41. data/spec/integration/association/many_to_one_spec.rb +110 -0
  42. data/spec/integration/association/one_to_many_spec.rb +58 -0
  43. data/spec/integration/association/one_to_one_spec.rb +57 -0
  44. data/spec/integration/association/one_to_one_through_spec.rb +90 -0
  45. data/spec/integration/combine_spec.rb +24 -24
  46. data/spec/integration/commands/create_spec.rb +215 -168
  47. data/spec/integration/commands/delete_spec.rb +88 -46
  48. data/spec/integration/commands/update_spec.rb +141 -60
  49. data/spec/integration/commands/upsert_spec.rb +83 -0
  50. data/spec/integration/gateway_spec.rb +9 -17
  51. data/spec/integration/migration_spec.rb +3 -5
  52. data/spec/integration/plugins/associates_spec.rb +168 -0
  53. data/spec/integration/plugins/auto_wrap_spec.rb +46 -0
  54. data/spec/integration/read_spec.rb +80 -77
  55. data/spec/integration/relation_schema_spec.rb +180 -0
  56. data/spec/integration/schema_inference_spec.rb +67 -0
  57. data/spec/integration/setup_spec.rb +22 -0
  58. data/spec/{support → integration/support}/active_support_notifications_spec.rb +0 -0
  59. data/spec/{support → integration/support}/rails_log_subscriber_spec.rb +0 -0
  60. data/spec/shared/database_setup.rb +46 -8
  61. data/spec/shared/relations.rb +8 -0
  62. data/spec/shared/users_and_accounts.rb +10 -0
  63. data/spec/shared/users_and_tasks.rb +20 -2
  64. data/spec/spec_helper.rb +64 -11
  65. data/spec/support/helpers.rb +9 -0
  66. data/spec/unit/association/many_to_many_spec.rb +89 -0
  67. data/spec/unit/association/many_to_one_spec.rb +81 -0
  68. data/spec/unit/association/name_spec.rb +68 -0
  69. data/spec/unit/association/one_to_many_spec.rb +62 -0
  70. data/spec/unit/association/one_to_one_spec.rb +62 -0
  71. data/spec/unit/association/one_to_one_through_spec.rb +69 -0
  72. data/spec/unit/association_errors_spec.rb +2 -4
  73. data/spec/unit/gateway_spec.rb +12 -3
  74. data/spec/unit/migration_tasks_spec.rb +3 -3
  75. data/spec/unit/migrator_spec.rb +2 -4
  76. data/spec/unit/{combined_associations_spec.rb → plugin/assoc_macros/combined_associations_spec.rb} +13 -19
  77. data/spec/unit/{many_to_many_spec.rb → plugin/assoc_macros/many_to_many_spec.rb} +9 -15
  78. data/spec/unit/{many_to_one_spec.rb → plugin/assoc_macros/many_to_one_spec.rb} +9 -14
  79. data/spec/unit/plugin/assoc_macros/one_to_many_spec.rb +78 -0
  80. data/spec/unit/plugin/base_view_spec.rb +11 -11
  81. data/spec/unit/plugin/pagination_spec.rb +62 -62
  82. data/spec/unit/relation_spec.rb +218 -146
  83. data/spec/unit/schema_spec.rb +15 -14
  84. data/spec/unit/types_spec.rb +40 -0
  85. metadata +105 -21
  86. data/.rubocop.yml +0 -74
  87. data/.rubocop_todo.yml +0 -21
  88. data/spec/unit/one_to_many_spec.rb +0 -83
@@ -1,11 +1,9 @@
1
- require 'spec_helper'
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
- configuration.relation(:users) do
6
+ conf.relation(:users) do
9
7
  use :assoc_macros
10
8
 
11
9
  def with_undefined
@@ -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) { DB_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(DB_URI, host: '127.0.0.1')
40
+ .with(POSTGRES_DB_URI, host: '127.0.0.1')
32
41
  .and_return(conn)
33
42
 
34
- gateway = ROM::SQL::Gateway.new(DB_URI, migrator: migrator, host: '127.0.0.1')
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(:configuration) { ROM::Configuration.new(:sql, DB_URI) }
11
- let!(:container) { ROM.container(configuration) }
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.stub(:env) { configuration }
15
+ allow(ROM::SQL::RakeSupport).to receive(:env) { conf }
16
16
  end
17
17
 
18
18
  context 'db:reset' do
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
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(DB_URI) }
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
@@ -1,18 +1,12 @@
1
- require 'spec_helper'
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
- configuration.relation(:users) { use :assoc_macros }
5
+ conf.relation(:users) { use :assoc_macros }
12
6
 
13
- configuration.relation(:tags) { use :assoc_macros }
7
+ conf.relation(:tags) { use :assoc_macros }
14
8
 
15
- configuration.relation(:tasks) do
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: 'Finish ROM', name: 'Piotr', tags_name: 'important' },
58
- { id: 2, title: 'Go to sleep', name: 'Piotr', tags_name: nil }
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: 'Go to sleep', name: 'Piotr', tags_name: nil },
63
- { id: 1, title: 'Finish ROM', name: 'Piotr', tags_name: 'important' }
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: 'Finish ROM', name: 'Piotr', tags_name: 'important' }
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: 'Finish ROM', name: 'Piotr' },
72
- { id: 2, title: 'Go to sleep', name: 'Piotr' }
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('Go to sleep').to_a).to eql(
76
- [{ id: 2, user_id: 1, title: 'Go to sleep' }]
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
- require 'spec_helper'
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
- configuration.relation(:tags) { use :assoc_macros }
12
- configuration.relation(:task_tags) { use :assoc_macros }
5
+ conf.relation(:tags) { use :assoc_macros }
6
+ conf.relation(:task_tags) { use :assoc_macros }
13
7
 
14
- configuration.relation(:tasks) do
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: 'Finish ROM', name: 'important' },
45
- { id: 2, title: 'Go to sleep', name: nil }
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: 'Finish ROM', tag_id: 1, name: 'important' },
50
- { id: 2, title: 'Go to sleep', tag_id: nil, name: nil }
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: 'Finish ROM', name: 'important' }
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
- require 'spec_helper'
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
- conn[:users].insert id: 2, name: 'Jane'
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
- configuration.relation(:tasks) do
9
+ conf.relation(:tasks) do
15
10
  use :assoc_macros
16
11
 
17
- many_to_one :users, key: :user_id, on: { name: 'Piotr' }
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
- configuration.mappers do
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: 1, name: 'Piotr', title: 'Finish ROM' }]
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: 1, title: 'Finish ROM', user: { name: 'Piotr' } }]
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
- configuration.relation(:task_tags) do
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
- configuration.relation(:tags) { use :assoc_macros }
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
- require 'spec_helper'
2
-
3
- describe 'Plugin / Base View' do
1
+ RSpec.describe 'Plugin / Base View' do
4
2
  include_context 'database setup'
5
3
 
6
- it 'defines base view' do
7
- module Test
8
- class Users < ROM::Relation[:sql]
9
- dataset :users
10
- register_as :users
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
- configuration.register_relation(Test::Users)
13
+ conf.register_relation(Test::Users)
15
14
 
16
- expect(container.relation(:users).base.header).to match_array([:id, :name])
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
- before do
9
- 9.times { |i| conn[:users].insert(name: "User #{i}") }
6
+ with_adapters do
7
+ before do
8
+ 9.times { |i| conn[:users].insert(name: "User #{i}") }
10
9
 
11
- configuration.relation(:users) do
12
- use :pagination
10
+ conf.relation(:users) do
11
+ use :pagination
13
12
 
14
- per_page 4
13
+ per_page 4
14
+ end
15
15
  end
16
- end
17
16
 
18
- describe '#page' do
19
- it 'allow to call with stringify number' do
20
- expect {
21
- container.relation(:users).page('5')
22
- }.to_not raise_error
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
- it 'preserves existing modifiers' do
26
- expect(
27
- container.relation(:users).send(:where, name: 'User 2').page(1).to_a.size
28
- ).to be(1)
29
- end
30
- end
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
- describe '#per_page' do
33
- it 'allow to call with stringify number' do
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
- it 'returns paginated relation with provided limit' do
40
- users = container.relation(:users).page(2).per_page(5)
41
+ expect(users.dataset.opts[:offset]).to eql(5)
42
+ expect(users.dataset.opts[:limit]).to eql(5)
41
43
 
42
- expect(users.dataset.opts[:offset]).to eql(5)
43
- expect(users.dataset.opts[:limit]).to eql(5)
44
+ expect(users.pager.current_page).to eql(2)
44
45
 
45
- expect(users.pager.current_page).to eql(2)
46
+ expect(users.pager.total).to be(9)
47
+ expect(users.pager.total_pages).to be(2)
46
48
 
47
- expect(users.pager.total).to be(9)
48
- expect(users.pager.total_pages).to be(2)
49
-
50
- expect(users.pager.next_page).to be(nil)
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
- describe '#total_pages' do
57
- it 'returns a single page when elements are a perfect fit' do
58
- users = container.relation(:users).page(1).per_page(3)
59
- expect(users.pager.total_pages).to eql(3)
60
- end
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
- it 'returns the exact number of pages to accommodate all elements' do
63
- users = container.relation(:users).per_page(9)
64
- expect(users.pager.total_pages).to eql(1)
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
- describe '#pager' do
69
- it 'returns a pager with pagination meta-info' do
70
- users = container.relation(:users).page(1)
67
+ describe '#pager' do
68
+ it 'returns a pager with pagination meta-info' do
69
+ users = container.relation(:users).page(1)
71
70
 
72
- expect(users.pager.total).to be(9)
73
- expect(users.pager.total_pages).to be(3)
71
+ expect(users.pager.total).to be(9)
72
+ expect(users.pager.total_pages).to be(3)
74
73
 
75
- expect(users.pager.current_page).to be(1)
76
- expect(users.pager.next_page).to be(2)
77
- expect(users.pager.prev_page).to be(nil)
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
- users = container.relation(:users).page(2)
78
+ users = container.relation(:users).page(2)
80
79
 
81
- expect(users.pager.current_page).to be(2)
82
- expect(users.pager.next_page).to be(3)
83
- expect(users.pager.prev_page).to be(1)
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
- users = container.relation(:users).page(3)
84
+ users = container.relation(:users).page(3)
86
85
 
87
- expect(users.pager.next_page).to be(nil)
88
- expect(users.pager.prev_page).to be(2)
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