with_model 1.2.1 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa91ae8171d006cf36ea0fe3f849f5087d5e2e42
4
- data.tar.gz: 9b709891a0c2eed053f23ab153d54aa7af0929d7
3
+ metadata.gz: 8e51eac83567f4ff6d4024540c3cb5f19af36d64
4
+ data.tar.gz: fd75b1167e99cdd310195b67a72bd50b9160dbbf
5
5
  SHA512:
6
- metadata.gz: 9c771d0886b9f2c57ba44c035c4fad21a6c83ac26af2234bbc07c22c267e433af91fbe8c30315422f433d5ff687adc62925a7e0c4e1c765b716203f5fac5501b
7
- data.tar.gz: f09b067cdfd82d425bc9ca698be041e4f809841bee41b7843d3595dcfd283ea9468d7102addcde1aa752a5defd98259ea99076e6354b8f418e4bd5bdf52b733d
6
+ metadata.gz: cc55b658c3f4fc470c31d2326a9b3efafa0948a0206d098cba84f1d796e3157e39940e48f509574a6b72b27331b3e4d820481aa60558baefa3e36f8d44a4d889
7
+ data.tar.gz: b041ee9cfb97ab592330e4a0b3ea75ee06248188c7bca52332e9b8ca9c217e87dcd201d1fa72f1ec82975ad16f01c1e6c14966bc0baadd3f47abad91e326d2c4
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format documentation
3
+ --order default
@@ -1,9 +1,12 @@
1
1
  language: ruby
2
+ sudo: false
2
3
 
3
4
  rvm:
4
- - "1.9"
5
- - "2.0"
6
- - "2.1"
5
+ - "2.3.1"
6
+ - "2.2.5"
7
+ - "2.1.10"
8
+ - "2.0.0-p648"
9
+ - "1.9.3-p551"
7
10
  - jruby-19mode
8
11
  - rbx-2
9
12
 
@@ -12,20 +15,35 @@ install:
12
15
 
13
16
  env:
14
17
  - ACTIVE_RECORD_BRANCH="master"
15
- - ACTIVE_RECORD_VERSION="~> 4.2.0"
16
- - ACTIVE_RECORD_VERSION="~> 4.1.0"
17
- - ACTIVE_RECORD_VERSION="~> 4.0.0"
18
- - ACTIVE_RECORD_VERSION="~> 3.2.0"
19
- - ACTIVE_RECORD_VERSION="~> 3.1.0"
20
18
  - ACTIVE_RECORD_VERSION="~> 3.0.0"
19
+ - ACTIVE_RECORD_VERSION="~> 3.1.0"
20
+ - ACTIVE_RECORD_VERSION="~> 3.2.0"
21
+ - ACTIVE_RECORD_VERSION="~> 4.0.0"
22
+ - ACTIVE_RECORD_VERSION="~> 4.1.0"
23
+ - ACTIVE_RECORD_VERSION="~> 4.2.0"
24
+ - ACTIVE_RECORD_VERSION="~> 5.0.0"
21
25
 
22
26
  matrix:
23
27
  allow_failures:
24
28
  - env: ACTIVE_RECORD_BRANCH="master"
25
29
  exclude:
26
30
  - env: ACTIVE_RECORD_BRANCH="master"
27
- rvm: "1.9"
31
+ rvm: "1.9.3-p551"
28
32
  - env: ACTIVE_RECORD_BRANCH="master"
29
- rvm: "2.0"
33
+ rvm: "2.0.0-p648"
34
+ - env: ACTIVE_RECORD_BRANCH="master"
35
+ rvm: "2.1.10"
36
+ - env: ACTIVE_RECORD_BRANCH="master"
37
+ rvm: jruby-19mode
30
38
  - env: ACTIVE_RECORD_BRANCH="master"
39
+ rvm: rbx-2
40
+ - env: ACTIVE_RECORD_VERSION="~> 5.0.0"
41
+ rvm: "1.9.3-p551"
42
+ - env: ACTIVE_RECORD_VERSION="~> 5.0.0"
43
+ rvm: "2.0.0-p648"
44
+ - env: ACTIVE_RECORD_VERSION="~> 5.0.0"
45
+ rvm: "2.1.10"
46
+ - env: ACTIVE_RECORD_VERSION="~> 5.0.0"
31
47
  rvm: jruby-19mode
48
+ - env: ACTIVE_RECORD_VERSION="~> 5.0.0"
49
+ rvm: rbx-2
@@ -1,3 +1,13 @@
1
+ ### 1.2.2
2
+
3
+ - Fix ActiveRecord 5 deprecation warning
4
+ - Options passed to `with_model` are validated to prevent accidental misuse of API
5
+ - Improve thread-safety by making table names unique to process and thread ID, instead of just process ID
6
+
7
+ ### 1.2.1
8
+
9
+ - Support ActiveRecord 4.2 (no code change, only dependency requirement bump)
10
+
1
11
  ### 1.2.0
2
12
 
3
13
  - Allow specifying scope for before/after blocks (Miks Miķelsons)
@@ -33,22 +43,20 @@
33
43
 
34
44
  ### 0.2.6
35
45
 
36
- - Active Record 3.2 compatible. (Steven Harman / Brent Wheeldon)
46
+ - ActiveRecord 3.2 compatible. (Steven Harman / Brent Wheeldon)
37
47
 
38
48
  ### 0.2.5
39
49
 
40
- - Clear Active Record 3.x associations class cache between specs to clean up test
41
- - pollution.
50
+ - Clear ActiveRecord 3.x associations class cache between specs to clean up test pollution.
42
51
 
43
52
  ### 0.2.4
44
53
 
45
54
  - Active Record 3.1 compatible.
46
- - Fix bug where column information was being cached incorrectly by Active
47
- - Record.
55
+ - Fix bug where column information was being cached incorrectly by ActiveRecord.
48
56
 
49
57
  ### 0.2.3
50
58
 
51
- - Create a new class each run to prevent test pollution. (J. Andrew Marshall)
59
+ - Create a new class each run to prevent test pollution. (Andrew Marshall)
52
60
  - Use :UpperCase in examples.
53
61
 
54
62
  ### 0.2.2
@@ -57,22 +65,19 @@
57
65
 
58
66
  ### 0.2.1
59
67
 
60
- - Fix a bug when the with_model name contains capital letters. Now you can
61
- - safely make calls like `with_model :BlogPost`
68
+ - Fix a bug when the with_model name contains capital letters. Now you can safely make calls like `with_model :BlogPost`
62
69
 
63
70
  ### 0.2
64
71
 
65
- - Remove the buggy attr_accessor method for accessing with_model classes. Now
66
- - there is only the constant available in the example group.
72
+ - Remove the buggy `attr_accessor` method for accessing with_model classes. Now there is only the constant available in the example group.
67
73
 
68
74
  ### 0.1.5
69
75
 
70
- - WithModel::Base is now marked as an abstract_class, which makes polymorphic
71
- - belongs_to work properly.
76
+ - `WithModel::Base` is now marked as an `abstract_class,` which makes polymorphic `belongs_to` work properly.
72
77
 
73
78
  ### 0.1.4
74
79
 
75
- - Add ability to pass arguments to create_table.
80
+ - Add ability to pass arguments to `create_table`.
76
81
 
77
82
  ### 0.1.2
78
83
 
data/Gemfile CHANGED
@@ -2,8 +2,22 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'activerecord', :git => 'https://github.com/rails/rails.git', :branch => ENV['ACTIVE_RECORD_BRANCH'] if ENV['ACTIVE_RECORD_BRANCH']
6
- gem 'activerecord', ENV['ACTIVE_RECORD_VERSION'] if ENV['ACTIVE_RECORD_VERSION']
7
5
  gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
8
6
  gem 'coveralls', :require => false, :platforms => :mri_20
9
- gem 'sqlite3', '1.3.8', :platforms => :ruby
7
+ gem 'test-unit', :require => 'test/unit'
8
+
9
+ if ar_branch = ENV['ACTIVE_RECORD_BRANCH']
10
+ gem 'activerecord', :git => 'https://github.com/rails/rails.git', :branch => ENV['ACTIVE_RECORD_BRANCH']
11
+ gem 'arel', :git => 'https://github.com/rails/arel.git' if ar_branch == 'master'
12
+ end
13
+
14
+ if ENV['ACTIVE_RECORD_VERSION']
15
+ gem 'activerecord', ENV['ACTIVE_RECORD_VERSION']
16
+ end
17
+
18
+ case RUBY_ENGINE
19
+ when 'ruby'
20
+ gem 'sqlite3', '>= 1.3.10', :platforms => :ruby
21
+ when 'rbx'
22
+ gem 'sqlite3', '1.3.8', :platforms => :ruby
23
+ end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2014 Case Commons, LLC
1
+ Copyright (c) 2010-2016 Case Commons, Inc. <http://casecommons.org>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # [with_model](https://github.com/Casecommons/with_model)
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/with_model.svg?style=flat)](https://rubygems.org/gems/with_model)
3
4
  [![Build Status](https://secure.travis-ci.org/Casecommons/with_model.svg?branch=master)](https://travis-ci.org/Casecommons/with_model)
4
5
  [![Code Climate](https://img.shields.io/codeclimate/github/Casecommons/with_model.svg?style=flat)](https://codeclimate.com/github/Casecommons/with_model)
5
6
  [![Coverage Status](https://img.shields.io/coveralls/Casecommons/with_model/master.svg?style=flat)](https://coveralls.io/r/Casecommons/with_model)
6
- [![Gem Version](https://img.shields.io/gem/v/with_model.svg?style=flat)](https://rubygems.org/gems/with_model)
7
7
 
8
8
  `with_model` dynamically builds an ActiveRecord model (with table) before each test in a group and destroys it afterwards.
9
9
 
@@ -165,9 +165,9 @@ end
165
165
 
166
166
  ## Requirements
167
167
 
168
- - Ruby 1.9.3+
168
+ - Ruby 1.9.3, 2.x
169
169
  - RSpec or minitest/spec
170
- - ActiveRecord 3.0.x4.1.x (for ActiveRecord 2, use with_model 0.2.x)
170
+ - ActiveRecord 3.x, 4.x (for ActiveRecord 2, use with_model 0.2.x)
171
171
 
172
172
  ## Versioning
173
173
 
@@ -175,5 +175,5 @@ As of version 1.0.0, with_model uses [Semantic Versioning 2.0.0](http://semver.o
175
175
 
176
176
  ## License
177
177
 
178
- Copyright © 2010–2014 Case Commons, LLC.
179
- Licensed under the MIT license, available in the “LICENSE file.
178
+ Copyright © 2010–2016 [Case Commons, Inc](http://casecommons.org).
179
+ Licensed under the MIT license, see [LICENSE](/LICENSE) file.
File without changes
@@ -6,29 +6,29 @@ require 'with_model/table'
6
6
 
7
7
  module WithModel
8
8
  class Model
9
+ OPTIONS = [:superclass].freeze
10
+ private_constant :OPTIONS
11
+
9
12
  attr_writer :model_block, :table_block, :table_options
10
13
 
11
14
  def initialize name, options = {}
15
+ validate_options!(options)
12
16
  @name = name.to_sym
13
- @options = options
14
17
  @model_block = nil
15
18
  @table_block = nil
16
19
  @table_options = {}
20
+ @superclass = options.fetch(:superclass, ActiveRecord::Base)
17
21
  end
18
22
 
19
23
  def create
20
24
  table.create
21
- @model = Class.new(superclass) do
25
+ @model = Class.new(@superclass) do
22
26
  extend WithModel::Methods
23
27
  end
24
28
  stubber.stub_const @model
25
29
  setup_model
26
30
  end
27
31
 
28
- def superclass
29
- @options.fetch(:superclass, ActiveRecord::Base)
30
- end
31
-
32
32
  def destroy
33
33
  stubber.unstub_const
34
34
  remove_from_superclass_descendants
@@ -68,7 +68,15 @@ module WithModel
68
68
  end
69
69
 
70
70
  def table_name
71
- "with_model_#{@name.to_s.tableize}_#{$$}".freeze
71
+ uid = "#$$_#{Thread.current.object_id}"
72
+ "with_model_#{@name.to_s.tableize}_#{uid}".freeze
73
+ end
74
+
75
+ def validate_options!(options)
76
+ unknown_options = options.keys - OPTIONS
77
+ unless unknown_options.empty?
78
+ raise ArgumentError, "unknown options: #{unknown_options.inspect}"
79
+ end
72
80
  end
73
81
  end
74
82
  end
@@ -9,13 +9,26 @@ module WithModel
9
9
  end
10
10
 
11
11
  def create
12
- connection = ActiveRecord::Base.connection
13
- connection.drop_table(@name) if connection.table_exists?(@name)
12
+ connection.drop_table(@name) if exists?
14
13
  connection.create_table(@name, @options, &@block)
15
14
  end
16
15
 
17
16
  def destroy
18
17
  ActiveRecord::Base.connection.drop_table(@name)
19
18
  end
19
+
20
+ private
21
+
22
+ def exists?
23
+ if connection.respond_to?(:data_source_exists?)
24
+ connection.data_source_exists?(@name)
25
+ else
26
+ connection.table_exists?(@name)
27
+ end
28
+ end
29
+
30
+ def connection
31
+ ActiveRecord::Base.connection
32
+ end
20
33
  end
21
34
  end
@@ -1,3 +1,3 @@
1
1
  module WithModel
2
- VERSION = '1.2.1'.freeze
2
+ VERSION = '1.2.2'.freeze
3
3
  end
@@ -56,7 +56,7 @@ describe "ActiveRecord behaviors" do
56
56
 
57
57
  with_model :TeaCup do
58
58
  table do |t|
59
- t.belongs_to :pet, :polymorphic => true
59
+ t.belongs_to :pet, :polymorphic => true, :index => false
60
60
  end
61
61
  model do
62
62
  belongs_to :pet, :polymorphic => true
@@ -86,26 +86,27 @@ describe "a temporary ActiveRecord model created with with_model" do
86
86
  end
87
87
  end
88
88
 
89
- ::MyConst = 1
89
+ describe "constant restoration" do
90
+ before { stub_const('MyConst', 1) }
91
+ shadowing_example_ran = false
90
92
 
91
- shadowing_example_ran = false
93
+ context "with the with_model block" do
94
+ with_model :MyConst
92
95
 
93
- describe "that shadows an existing constant" do
94
- with_model :MyConst
96
+ after do
97
+ shadowing_example_ran = true
98
+ end
95
99
 
96
- after do
97
- shadowing_example_ran = true
100
+ it "shadows that constant" do
101
+ expect(MyConst).to be_a(Class)
102
+ end
98
103
  end
99
104
 
100
- it "shadows that constant" do
101
- expect(MyConst).to be_a(Class)
102
- end
103
- end
104
-
105
- context "in later examples" do
106
- it "returns the constant to its original value" do
107
- expect(shadowing_example_ran).to eq true
108
- expect(MyConst).to eq 1
105
+ context "without the with_model block" do
106
+ it "returns the constant to its original value" do
107
+ expect(shadowing_example_ran).to eq true
108
+ expect(MyConst).to eq 1
109
+ end
109
110
  end
110
111
  end
111
112
 
@@ -150,40 +151,41 @@ describe "a temporary ActiveRecord model created with with_model" do
150
151
  it "is available" do end
151
152
  end
152
153
 
153
- module AMixin
154
- def foo
154
+ context "with a mixin" do
155
+ let(:mixin) do
156
+ Module.new { def foo; end }
155
157
  end
156
- end
158
+ before { stub_const('AMixin', mixin) }
157
159
 
158
- context "with a mixin" do
159
160
  with_model :WithAMixin do
160
161
  model do
161
162
  include AMixin
162
163
  end
163
164
  end
164
165
 
165
- before { ::ModelWithMixin = WithAMixin }
166
-
167
166
  it "has the mixin" do
168
- expect(lambda { ::ModelWithMixin.new.foo }).to_not raise_error
169
- expect(::ModelWithMixin.include?(AMixin)).to eq true
167
+ expect(lambda { ::WithAMixin.new.foo }).to_not raise_error
168
+ expect(::WithAMixin.include?(AMixin)).to eq true
170
169
  end
171
170
  end
172
171
 
173
172
  context "with a mixin that has a class_eval" do
174
- subject { WithAClassEval.new }
175
-
176
- module AMixinWithClassEval
177
- def self.included(klass)
178
- klass.class_eval do
179
- after_save { |object| object.my_method }
173
+ let(:mixin) do
174
+ Module.new do
175
+ def self.included(klass)
176
+ klass.class_eval do
177
+ after_save { |object| object.my_method }
178
+ end
180
179
  end
181
180
  end
182
181
  end
182
+ before { stub_const('AMixin', mixin) }
183
+
184
+ subject { WithAClassEval.new }
183
185
 
184
186
  with_model :WithAClassEval do
185
187
  model do
186
- include AMixinWithClassEval
188
+ include AMixin
187
189
  def my_method; end
188
190
  end
189
191
  end
@@ -329,6 +331,10 @@ describe "a temporary ActiveRecord model created with with_model" do
329
331
  self.abstract_class = true
330
332
  end
331
333
 
334
+ after(:all) do
335
+ Object.send(:remove_const, 'BlogPostParent')
336
+ end
337
+
332
338
  with_model :BlogPost, superclass: BlogPostParent do
333
339
  table do |t|
334
340
  t.string 'title'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Case Commons, LLC
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-29 00:00:00.000000000 Z
12
+ date: 2016-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -83,7 +83,7 @@ files:
83
83
  - Gemfile
84
84
  - LICENSE
85
85
  - README.md
86
- - Rakefile
86
+ - Rakefile.rb
87
87
  - lib/with_model.rb
88
88
  - lib/with_model/constant_stubber.rb
89
89
  - lib/with_model/methods.rb
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.4.4
119
+ rubygems_version: 2.5.2
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Dynamically build a model within an RSpec context
@@ -125,4 +125,3 @@ test_files:
125
125
  - spec/readme_spec.rb
126
126
  - spec/spec_helper.rb
127
127
  - spec/with_model_spec.rb
128
- has_rdoc: