arel-helpers 2.9.1 → 2.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  class TestQueryBuilder < ArelHelpers::QueryBuilder
@@ -13,48 +11,63 @@ class TestQueryBuilder < ArelHelpers::QueryBuilder
13
11
  def noop
14
12
  reflect(query)
15
13
  end
14
+
15
+ not_nil def optional(skip:)
16
+ reflect(query.where(title: 'BarBar')) unless skip
17
+ end
16
18
  end
17
19
 
18
20
  describe ArelHelpers::QueryBuilder do
19
21
  let(:builder) { TestQueryBuilder.new }
20
22
 
21
- it "returns (i.e. reflects) new instances of QueryBuilder" do
23
+ it 'returns (i.e. reflects) new instances of QueryBuilder' do
22
24
  builder.tap do |original_builder|
23
25
  original_builder.params = true
24
26
  new_builder = original_builder.noop
25
- new_builder.object_id.should_not == original_builder.object_id
26
- new_builder.params?.should == true
27
+ expect(new_builder.object_id).not_to eq original_builder.object_id
28
+ expect(new_builder.params?).to be true
27
29
  end
28
30
  end
29
31
 
30
- it "forwards #to_a" do
31
- Post.create(title: "Foobar")
32
+ it 'forwards #to_a' do
33
+ Post.create(title: 'Foobar')
32
34
  builder.to_a.tap do |posts|
33
- posts.size.should == 1
34
- posts.first.title.should == "Foobar"
35
+ expect(posts.size).to eq 1
36
+ expect(posts.first.title).to eq 'Foobar'
35
37
  end
36
38
  end
37
39
 
38
- it "forwards #to_sql" do
39
- builder.to_sql.strip.should == 'SELECT "posts".* FROM "posts"'
40
+ it 'forwards #to_sql' do
41
+ expect(builder.to_sql.strip).to eq 'SELECT "posts".* FROM "posts"'
40
42
  end
41
43
 
42
- it "forwards #each" do
43
- created_post = Post.create(title: "Foobar")
44
+ it 'forwards #each' do
45
+ created_post = Post.create(title: 'Foobar')
44
46
  builder.each do |post|
45
- post.should == created_post
47
+ expect(post).to eq created_post
46
48
  end
47
49
  end
48
50
 
49
- it "forwards other enumerable methods via #each" do
50
- Post.create(title: "Foobar")
51
- builder.map(&:title).should == ["Foobar"]
51
+ it 'forwards other enumerable methods via #each' do
52
+ Post.create(title: 'Foobar')
53
+ expect(builder.map(&:title)).to eq ['Foobar']
52
54
  end
53
55
 
54
56
  ArelHelpers::QueryBuilder::TERMINAL_METHODS.each do |method|
55
57
  it "does not enumerate records for #{method}" do
56
- mock(builder).each.never
58
+ allow(builder).to receive :each
57
59
  builder.public_send(method)
60
+ expect(builder).not_to have_received :each
58
61
  end
59
62
  end
63
+
64
+ it 'returns reflect on existing query if method returns a falsy value' do
65
+ expect(builder.optional(skip: true).to_sql.strip).to eq 'SELECT "posts".* FROM "posts"'
66
+ end
67
+
68
+ it 'returns reflect on new query for default chainable method if value is truthy' do
69
+ expect(builder.optional(skip: false).to_sql.strip.gsub(/\s+/, ' ')).to eq <<-SQL.squish
70
+ SELECT "posts".* FROM "posts" WHERE "posts"."title" = 'BarBar'
71
+ SQL
72
+ end
60
73
  end
data/spec/spec_helper.rb CHANGED
@@ -1,30 +1,20 @@
1
- # encoding: UTF-8
2
-
3
- $:.push(File.dirname(__FILE__))
1
+ $LOAD_PATH.push(File.dirname(__FILE__))
4
2
 
5
3
  require 'rspec'
6
4
  require 'arel-helpers'
7
5
  require 'fileutils'
8
- require 'pry-byebug'
9
6
 
10
- require 'env'
7
+ require 'combustion'
8
+ Combustion.initialize! :active_record
11
9
 
12
- def silence(&block)
13
- original_stdout = $stdout
14
- $stdout = StringIO.new
15
- begin
16
- yield
17
- ensure
18
- $stdout = original_stdout
19
- end
20
- end
10
+ require 'database_cleaner'
11
+ require 'env/models'
21
12
 
22
13
  RSpec.configure do |config|
23
- config.mock_with :rr
14
+ DatabaseCleaner.strategy = :transaction
15
+
16
+ config.before(:suite) { DatabaseCleaner.clean_with :truncation }
24
17
 
25
- config.before(:each) do
26
- ArelHelpers::Env.establish_connection
27
- ArelHelpers::Env.reset
28
- silence { ArelHelpers::Env.migrate }
29
- end
18
+ config.before { DatabaseCleaner.start }
19
+ config.after { DatabaseCleaner.clean }
30
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.1
4
+ version: 2.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-11 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,6 +30,90 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: appraisal
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: combustion
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: database_cleaner
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.8'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.8'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3'
103
+ - !ruby/object:Gem::Dependency
104
+ name: sqlite3
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.4.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 1.4.0
33
117
  description: Useful tools to help construct database queries with ActiveRecord and
34
118
  Arel.
35
119
  email:
@@ -51,9 +135,11 @@ files:
51
135
  - lib/arel-helpers/version.rb
52
136
  - spec/aliases_spec.rb
53
137
  - spec/arel_table_spec.rb
54
- - spec/env.rb
55
- - spec/env/migrations.rb
56
138
  - spec/env/models.rb
139
+ - spec/internal/config/database.yml
140
+ - spec/internal/db/combustion_test.sqlite
141
+ - spec/internal/db/schema.rb
142
+ - spec/internal/log/test.log
57
143
  - spec/join_association_spec.rb
58
144
  - spec/query_builder_spec.rb
59
145
  - spec/spec_helper.rb
@@ -61,7 +147,7 @@ homepage: https://github.com/camertron/arel-helpers
61
147
  licenses:
62
148
  - MIT
63
149
  metadata: {}
64
- post_install_message:
150
+ post_install_message:
65
151
  rdoc_options: []
66
152
  require_paths:
67
153
  - lib
@@ -76,9 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
162
  - !ruby/object:Gem::Version
77
163
  version: '0'
78
164
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.7.6
81
- signing_key:
165
+ rubygems_version: 3.2.22
166
+ signing_key:
82
167
  specification_version: 4
83
168
  summary: Useful tools to help construct database queries with ActiveRecord and Arel.
84
169
  test_files: []
@@ -1,75 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- SuperClass = if ActiveRecord::VERSION::MAJOR >= 5
4
- ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}".to_f]
5
- else
6
- ActiveRecord::Migration
7
- end
8
-
9
- class CreatePostsTable < SuperClass
10
- def change
11
- create_table :posts do |t|
12
- t.column :title, :string
13
- end
14
- end
15
- end
16
-
17
- class CreateCommentsTable < SuperClass
18
- def change
19
- create_table :comments do |t|
20
- t.references :post
21
- end
22
- end
23
- end
24
-
25
- class CreateAuthorsTable < SuperClass
26
- def change
27
- create_table :authors do |t|
28
- t.references :comment
29
- t.references :collab_posts
30
- end
31
- end
32
- end
33
-
34
- class CreateFavoritesTable < SuperClass
35
- def change
36
- create_table :favorites do |t|
37
- t.references :post
38
- end
39
- end
40
- end
41
-
42
- class CreateCollabPostsTable < SuperClass
43
- def change
44
- create_table :collab_posts do |t|
45
- t.references :authors
46
- end
47
- end
48
- end
49
-
50
- class CreateCardsTable < SuperClass
51
- def change
52
- create_table :cards
53
- end
54
- end
55
-
56
- class CreateCardLocationsTable < SuperClass
57
- def change
58
- create_table :card_locations do |t|
59
- t.references :location
60
- t.references :card, polymorphic: true
61
- end
62
- end
63
- end
64
-
65
- class CreateLocationsTable < SuperClass
66
- def change
67
- create_table :locations
68
- end
69
- end
70
-
71
- class CreateCommunityTicketsTable < SuperClass
72
- def change
73
- create_table :community_tickets
74
- end
75
- end
data/spec/env.rb DELETED
@@ -1,44 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'env/migrations'
4
- require 'env/models'
5
-
6
- module ArelHelpers
7
- class Env
8
- class << self
9
-
10
- def db_dir
11
- @db_dir ||= File.join(File.dirname(File.dirname(__FILE__)), "tmp")
12
- end
13
-
14
- def db_file
15
- @db_file ||= File.join(db_dir, "test.sqlite3")
16
- end
17
-
18
- def establish_connection
19
- ActiveRecord::Base.establish_connection(
20
- :adapter => "sqlite3",
21
- :database => db_file
22
- )
23
- end
24
-
25
- def migrate
26
- CreatePostsTable.new.change
27
- CreateCommentsTable.new.change
28
- CreateAuthorsTable.new.change
29
- CreateFavoritesTable.new.change
30
- CreateCollabPostsTable.new.change
31
- CreateCardsTable.new.change
32
- CreateCardLocationsTable.new.change
33
- CreateLocationsTable.new.change
34
- CreateCommunityTicketsTable.new.change
35
- end
36
-
37
- def reset
38
- File.unlink(db_file) if File.exist?(db_file)
39
- FileUtils.mkdir_p(db_dir)
40
- end
41
-
42
- end
43
- end
44
- end