transactional_capybara 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b47fe9a7d758b60e2a61d02a9efc54683c04c958
4
- data.tar.gz: 2fad7e2694272847292391264521c9edac1ec55b
3
+ metadata.gz: 7c9cf729d42a0122c754de2e83c0a04915e31e4a
4
+ data.tar.gz: d37be5f09cf6c06743ebbc1bb7e0f03ba67e7af8
5
5
  SHA512:
6
- metadata.gz: 489e7e2d50f51dcb9d15fe8eb9198d2b09c71b394157e704ecbe9360e8070b63f8890f60834f9889ec560ced5fe84881610b7b35cf19a4be325d391272597672
7
- data.tar.gz: d2fd46c45b0cc39fa8acfe71b538be2988cd9fa956571693378936e4a9a7f319462245122927b3eb074eea7296bbb25527743ca1cb46b31a21a129b880949c01
6
+ metadata.gz: a4d7ff9a275cb53bee768731c3fe9098620d2b7feb2c6cc12cdb87d3acaf4d6d0a10fc6e8caec1ef5f86b22ece3791c09b304989df8c14fe03e82544c3a760de
7
+ data.tar.gz: d1cc0c121d663faa17a143229d1e3a7760a36a344ee1eacd59152729eff19e5b507bbbf7c6b4a71f2be56dbfa5238ba4cfd2e80f4da24ee2221ea9b81d64fe18
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transactional_capybara (0.1.0.pre.3)
4
+ transactional_capybara (0.1.0)
5
5
  capybara
6
6
 
7
7
  GEM
@@ -76,6 +76,7 @@ GEM
76
76
  multi_json (~> 1.0)
77
77
  rubyzip (~> 1.0)
78
78
  websocket (~> 1.0)
79
+ sequel (4.42.1)
79
80
  sinatra (1.4.6)
80
81
  rack (~> 1.4)
81
82
  rack-protection (~> 1.4)
@@ -105,6 +106,7 @@ DEPENDENCIES
105
106
  rake
106
107
  rspec
107
108
  selenium-webdriver
109
+ sequel
108
110
  sinatra
109
111
  sqlite3
110
112
  transactional_capybara!
data/README.md CHANGED
@@ -11,6 +11,20 @@ Use this instead.
11
11
 
12
12
  For a detailed explanation of how this works, refer to the [introductory blog post].
13
13
 
14
+ ## Support ##
15
+
16
+ Right now this gem automatically handles the following things:
17
+
18
+ * ActiveRecord
19
+ * Sequel
20
+ * jQuery
21
+ * Angular
22
+
23
+ Tested on Capybara 2.4.x, may not work on other major versions.
24
+
25
+ Don't see something you want?
26
+ I'd love a pull request, or even just a friendly inquiry!
27
+
14
28
  ## Setup ##
15
29
 
16
30
  Add it to your Gemfile, of course:
@@ -138,19 +152,9 @@ after :each do
138
152
  end
139
153
  ```
140
154
 
141
-
142
- ## Support ##
143
-
144
- Right now this gem automatically fixes the following things:
145
-
146
- * ActiveRecord
147
- * jQuery
148
- * Angular
149
-
150
- Tested on Capybara 2.4.x, may not work on other major versions.
151
-
152
- Don't see something you want?
153
- I'd love a pull request, or even just a friendly inquiry!
155
+ ## Sequel ##
156
+ If you want to have shared database connections with sequel just
157
+ add the option `single_threaded: true` to your sequel connection in test.
154
158
 
155
159
  ## Contributing
156
160
 
data/Rakefile CHANGED
@@ -9,14 +9,17 @@ namespace :test do
9
9
  desc "Run tests against all drivers and all databases listed in the config"
10
10
  task :all do
11
11
  db_config = YAML.load_file(File.join(File.dirname(__FILE__), "spec/config.yml"))
12
- db_config["database"].keys.each do |db_name|
12
+ configs = db_config["database"].keys.product(
13
+ %w[selenium webkit poltergeist],
14
+ %w[active_record sequel]
15
+ )
16
+ configs.each do |db_name, driver, orm|
13
17
  ENV['DB'] = db_name
14
- %w[selenium webkit poltergeist].each do |driver|
15
- ENV['DRIVER'] = driver
16
- puts ENV.to_hash.slice 'DRIVER', 'DB'
17
- Rake::Task['test:rspec'].reenable
18
- Rake::Task['test:rspec'].invoke
19
- end
18
+ ENV['DRIVER'] = driver
19
+ ENV['ORM'] = orm
20
+ puts ENV.to_hash.slice 'DRIVER', 'DB', 'ORM'
21
+ Rake::Task['test:rspec'].reenable
22
+ Rake::Task['test:rspec'].invoke
20
23
  end
21
24
  end
22
25
 
@@ -1,15 +1,12 @@
1
- class ActiveRecord::Base
2
- mattr_accessor :shared_connection
3
- @@shared_connection = nil
4
-
5
- def self.connection
6
- @@shared_connection || retrieve_connection
7
- end
8
- end
9
-
10
1
  module TransactionalCapybara
11
2
  module_function
12
3
  def share_connection
13
- ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
4
+ #noop is default
14
5
  end
15
6
  end
7
+ if defined?(ActiveRecord::Base)
8
+ require_relative './shared_connection/active_record'
9
+ end
10
+ if defined?(Sequel::Model)
11
+ require_relative './shared_connection/sequel'
12
+ end
@@ -0,0 +1,15 @@
1
+ class ActiveRecord::Base
2
+ mattr_accessor :shared_connection
3
+ @@shared_connection = nil
4
+
5
+ def self.connection
6
+ @@shared_connection || retrieve_connection
7
+ end
8
+ end
9
+
10
+ module TransactionalCapybara
11
+ module_function
12
+ def share_connection
13
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module TransactionalCapybara
2
+ module_function
3
+ def share_connection
4
+ warn 'WARNING: No database connection sharing enabled! You propably want to use the sequel connection option single_threaded: true' unless Sequel::Model.db.single_threaded?
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module TransactionalCapybara
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,7 +6,9 @@ database:
6
6
  username: travis
7
7
  database: transactional_capybara_test
8
8
  sqlite:
9
- adapter: sqlite3
9
+ adapter:
10
+ active_record: sqlite3
11
+ sequel: sqlite
10
12
  database: ":memory:"
11
13
  postgres:
12
14
  adapter: postgresql
@@ -1,5 +1,4 @@
1
1
  require_relative 'support/server'
2
- require_relative 'support/model'
3
2
 
4
3
  RSpec.describe "server with AJAX", type: :feature, js: true do
5
4
  before do
@@ -7,7 +7,9 @@ database:
7
7
  password: abcd1234
8
8
  database: transactional_capybara
9
9
  sqlite:
10
- adapter: sqlite3
10
+ adapter:
11
+ active_record: sqlite3
12
+ sequel: sqlite
11
13
  host: localhost
12
14
  database: tmp/test.db
13
15
  postgres:
@@ -1,11 +1,8 @@
1
1
  require 'yaml'
2
- db_type = ENV['DB'] || 'sqlite'
3
- db_config = YAML.load_file(File.join(File.dirname(__FILE__), "config.yml"))
4
- db = db_config["database"][db_type]
2
+ ENV['DB'] ||= 'sqlite'
3
+ ENV['ORM'] ||= 'active_record'
5
4
 
6
- require 'active_record'
7
- ActiveRecord::Base.establish_connection(db)
8
- load File.join(File.dirname(__FILE__), "support/schema.rb")
5
+ require_relative "support/#{ENV['ORM']}_setup.rb"
9
6
 
10
7
  require 'capybara/rspec'
11
8
  require 'capybara/poltergeist'
@@ -0,0 +1,13 @@
1
+ require 'active_record'
2
+ require_relative 'db_config'
3
+
4
+ config = db_config('active_record')
5
+ ActiveRecord::Base.establish_connection(config)
6
+
7
+ ActiveRecord::Schema.define do
8
+ create_table :test_values, :force => true do |t|
9
+ t.string :content
10
+ end
11
+ end
12
+
13
+ require_relative 'model/active_record'
@@ -0,0 +1,6 @@
1
+ def db_config orm
2
+ db_config = YAML.load_file(File.join(File.dirname(__FILE__), "../config.yml"))
3
+ db = db_config["database"][ENV['DB']]
4
+ db["adapter"] = db["adapter"][ENV['ORM']] unless db["adapter"].is_a? String
5
+ db
6
+ end
@@ -0,0 +1,5 @@
1
+ class TestValue < Sequel::Model
2
+ def self.create!(data)
3
+ new(data).save(raise_on_failure: true)
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'sequel'
2
+ require_relative 'db_config'
3
+
4
+ config = db_config('sequel').merge(single_threaded: true)
5
+ db = Sequel.connect(config)
6
+
7
+ db.create_table! :test_values do
8
+ primary_key :id
9
+ String :content
10
+ end
11
+ require_relative 'model/sequel'
@@ -1,11 +1,12 @@
1
1
  require 'sinatra'
2
2
  require 'tilt/erb'
3
- require_relative 'model'
4
3
 
5
4
  class AjaxServer < Sinatra::Base
6
5
  set :public_folder, File.dirname(__FILE__) + '/vendor'
7
6
 
8
- cattr_accessor :should_return_from_ajax
7
+ class << self
8
+ attr_accessor :should_return_from_ajax
9
+ end
9
10
 
10
11
  get "/boring_page" do
11
12
  erb "Hi", layout: :basic
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "sinatra"
26
26
  spec.add_development_dependency "rspec"
27
27
  spec.add_development_dependency "activerecord"
28
+ spec.add_development_dependency "sequel"
28
29
  spec.add_development_dependency "mysql2"
29
30
  spec.add_development_dependency "sqlite3"
30
31
  spec.add_development_dependency "pg"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transactional_capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Young
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-09 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sequel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: mysql2
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -198,14 +212,19 @@ files:
198
212
  - lib/transactional_capybara/ajax_helpers.rb
199
213
  - lib/transactional_capybara/rspec.rb
200
214
  - lib/transactional_capybara/shared_connection.rb
215
+ - lib/transactional_capybara/shared_connection/active_record.rb
216
+ - lib/transactional_capybara/shared_connection/sequel.rb
201
217
  - lib/transactional_capybara/version.rb
202
218
  - spec/.travis.config.yml
203
219
  - spec/ajax_spec.rb
204
220
  - spec/config.yml.example
205
221
  - spec/spec_helper.rb
222
+ - spec/support/active_record_setup.rb
223
+ - spec/support/db_config.rb
206
224
  - spec/support/migration.rb
207
- - spec/support/model.rb
208
- - spec/support/schema.rb
225
+ - spec/support/model/active_record.rb
226
+ - spec/support/model/sequel.rb
227
+ - spec/support/sequel_setup.rb
209
228
  - spec/support/server.rb
210
229
  - spec/support/vendor/angular.js
211
230
  - spec/support/vendor/jquery.js
@@ -244,9 +263,12 @@ test_files:
244
263
  - spec/ajax_spec.rb
245
264
  - spec/config.yml.example
246
265
  - spec/spec_helper.rb
266
+ - spec/support/active_record_setup.rb
267
+ - spec/support/db_config.rb
247
268
  - spec/support/migration.rb
248
- - spec/support/model.rb
249
- - spec/support/schema.rb
269
+ - spec/support/model/active_record.rb
270
+ - spec/support/model/sequel.rb
271
+ - spec/support/sequel_setup.rb
250
272
  - spec/support/server.rb
251
273
  - spec/support/vendor/angular.js
252
274
  - spec/support/vendor/jquery.js
@@ -1,5 +0,0 @@
1
- ActiveRecord::Schema.define do
2
- create_table :test_values, :force => true do |t|
3
- t.string :content
4
- end
5
- end