with_model 2.1.7 → 2.3.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.
data/test/sti_test.rb ADDED
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ # Stands in for an application's own model, the usual reason to want single table
6
+ # inheritance: its table is created once and outlives every test here, so a
7
+ # with_model child's rows cannot be disposed of by dropping the table.
8
+ module AppModels
9
+ class Cupboard < ActiveRecord::Base
10
+ end
11
+ end
12
+
13
+ ActiveRecord::Base.connection.create_table AppModels::Cupboard.table_name, force: true do |t|
14
+ t.string "type"
15
+ t.string "name"
16
+ end
17
+
18
+ # A with_model parent and an STI child in the same test case. The child's
19
+ # superclass is resolved per-example, so this only works if the parent is
20
+ # created before the child and destroyed after it.
21
+ class StiTest < Minitest::Test
22
+ with_model :Vehicle do
23
+ table do |t|
24
+ t.string "type"
25
+ t.string "name"
26
+ end
27
+ end
28
+
29
+ with_model :Truck, superclass: -> { Vehicle } do
30
+ table(false)
31
+ end
32
+
33
+ with_model :Chest, superclass: "AppModels::Cupboard" do
34
+ table(false)
35
+ end
36
+
37
+ def test_the_child_shares_the_parents_table
38
+ assert_equal Vehicle.table_name, Truck.table_name
39
+ end
40
+
41
+ def test_the_child_stores_its_own_type
42
+ truck = Truck.create!(name: "Ford F-150")
43
+
44
+ assert_equal "Truck", truck.reload.type
45
+ assert_instance_of Truck, Vehicle.first
46
+ end
47
+
48
+ # Rows in a table the child does not own have to be deleted when it goes away,
49
+ # since nothing else will: Cupboard's table is still standing afterwards, and a
50
+ # row naming a class that no longer exists makes it unloadable. Both tests write
51
+ # one and first insist the table is empty, so whichever minitest happens to run
52
+ # second fails if the rows survived teardown - whatever order the seed picks.
53
+ def test_the_childs_rows_do_not_outlive_it
54
+ assert_empty AppModels::Cupboard.all, "a previous test's rows outlived it"
55
+
56
+ Chest.create!(name: "sideboard")
57
+
58
+ assert_equal 1, AppModels::Cupboard.count
59
+ end
60
+
61
+ def test_the_childs_rows_leave_the_superclass_loadable
62
+ assert_empty AppModels::Cupboard.all, "a previous test's rows outlived it"
63
+
64
+ Chest.create!(name: "wardrobe")
65
+
66
+ assert_instance_of Chest, AppModels::Cupboard.first
67
+ end
68
+ end
data/test/test_helper.rb CHANGED
@@ -1,28 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
4
 
5
- # Workaround for JRuby CI failure https://github.com/jruby/jruby/issues/6547#issuecomment-774104996
6
- if RUBY_ENGINE == 'jruby'
7
- require 'i18n/backend'
8
- require 'i18n/backend/simple'
9
- end
10
-
11
- require 'with_model'
12
- require 'minitest/autorun'
5
+ require "with_model"
6
+ require "minitest/autorun"
13
7
 
14
8
  WithModel.runner = :minitest
15
9
 
16
- module MiniTest
17
- class Test
18
- extend WithModel
19
- end
20
- end
10
+ WithModel.deprecator.behavior = :raise
21
11
 
22
- is_jruby = RUBY_PLATFORM == 'java'
23
- adapter = is_jruby ? 'jdbcsqlite3' : 'sqlite3'
12
+ Minitest::Test.class_eval do
13
+ extend WithModel
14
+ end
24
15
 
25
16
  # WithModel requires ActiveRecord::Base.connection to be established.
26
17
  # If ActiveRecord already has a connection, as in a Rails app, this is unnecessary.
27
- require 'active_record'
28
- ActiveRecord::Base.establish_connection(adapter: adapter, database: ':memory:')
18
+ require "active_record"
19
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
- class WithModelTest < MiniTest::Test
5
+ class WithModelTest < Minitest::Test
6
6
  with_model :BlogPost do
7
7
  table do |t|
8
- t.string 'title'
9
- t.text 'content'
8
+ t.string "title"
9
+ t.text "content"
10
10
  t.timestamps null: false
11
11
  end
12
12
 
@@ -17,13 +17,13 @@ class WithModelTest < MiniTest::Test
17
17
  end
18
18
  end
19
19
 
20
- def test_it_should_act_like_a_normal_active_record_model # rubocop:disable Minitest/MultipleAssertions
21
- record = BlogPost.create!(title: 'New blog post', content: 'Hello, world!')
20
+ def test_it_should_act_like_a_normal_active_record_model
21
+ record = BlogPost.create!(title: "New blog post", content: "Hello, world!")
22
22
 
23
23
  record.reload
24
24
 
25
- assert_equal 'New blog post', record.title
26
- assert_equal 'Hello, world!', record.content
25
+ assert_equal "New blog post", record.title
26
+ assert_equal "Hello, world!", record.content
27
27
  assert record.updated_at
28
28
 
29
29
  record.destroy
@@ -34,6 +34,6 @@ class WithModelTest < MiniTest::Test
34
34
  end
35
35
 
36
36
  def test_it_has_the_methods_defined_in_its_model_block
37
- assert_equal 'Title: New blog post', BlogPost.new(title: 'New blog post').fancy_title
37
+ assert_equal "Title: New blog post", BlogPost.new(title: "New blog post").fancy_title
38
38
  end
39
39
  end
data/with_model.gemspec CHANGED
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push File.expand_path('lib', __dir__)
4
- require 'with_model/version'
3
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
4
+ require "with_model/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = 'with_model'
8
- spec.version = WithModel::VERSION
9
- spec.authors = ['Case Commons, LLC', 'Grant Hutchins', 'Andrew Marshall']
10
- spec.email = %w[casecommons-dev@googlegroups.com gems@nertzy.com andrew@johnandrewmarshall.com]
11
- spec.homepage = 'https://github.com/Casecommons/with_model'
12
- spec.summary = 'Dynamically build a model within an RSpec context'
7
+ spec.name = "with_model"
8
+ spec.version = WithModel::VERSION
9
+ spec.authors = ["Case Commons, LLC", "Grant Hutchins", "Andrew Marshall"]
10
+ spec.email = %w[casecommons-dev@googlegroups.com gems@nertzy.com andrew@johnandrewmarshall.com]
11
+ spec.homepage = "https://github.com/Casecommons/with_model"
12
+ spec.summary = "Dynamically build a model within an RSpec context"
13
13
  spec.description = spec.summary
14
- spec.license = 'MIT'
15
- spec.metadata['rubygems_mfa_required'] = 'true'
14
+ spec.license = "MIT"
15
+ spec.metadata["rubygems_mfa_required"] = "true"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ['lib']
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = '>= 2.7'
21
+ spec.required_ruby_version = ">= 3.3"
22
22
 
23
- spec.add_dependency 'activerecord', '>= 6.0'
23
+ spec.add_dependency "activerecord", ">= 7.2"
24
24
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Case Commons, LLC
8
8
  - Grant Hutchins
9
9
  - Andrew Marshall
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2023-09-15 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
@@ -18,14 +17,14 @@ dependencies:
18
17
  requirements:
19
18
  - - ">="
20
19
  - !ruby/object:Gem::Version
21
- version: '6.0'
20
+ version: '7.2'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
- version: '6.0'
27
+ version: '7.2'
29
28
  description: Dynamically build a model within an RSpec context
30
29
  email:
31
30
  - casecommons-dev@googlegroups.com
@@ -41,27 +40,34 @@ files:
41
40
  - ".gitignore"
42
41
  - ".jrubyrc"
43
42
  - ".rspec"
44
- - ".rubocop.yml"
45
- - ".rubocop_todo.yml"
46
43
  - ".yardopts"
47
44
  - CHANGELOG.md
45
+ - CONTRIBUTING.md
48
46
  - Gemfile
49
47
  - LICENSE
50
48
  - README.md
51
49
  - Rakefile
52
50
  - lib/with_model.rb
53
51
  - lib/with_model/constant_stubber.rb
52
+ - lib/with_model/descendants_tracker.rb
53
+ - lib/with_model/invalid_superclass.rb
54
54
  - lib/with_model/methods.rb
55
+ - lib/with_model/missing_superclass.rb
55
56
  - lib/with_model/model.rb
56
57
  - lib/with_model/model/dsl.rb
58
+ - lib/with_model/null_table.rb
57
59
  - lib/with_model/table.rb
58
60
  - lib/with_model/version.rb
59
- - spec/.rubocop.yml
60
61
  - spec/active_record_behaviors_spec.rb
61
62
  - spec/constant_stubber_spec.rb
63
+ - spec/descendants_tracking_spec.rb
62
64
  - spec/readme_spec.rb
63
65
  - spec/spec_helper.rb
66
+ - spec/table_false_spec.rb
64
67
  - spec/with_model_spec.rb
68
+ - test/declaration_order_test.rb
69
+ - test/spec_dsl_test.rb
70
+ - test/sti_test.rb
65
71
  - test/test_helper.rb
66
72
  - test/with_model_test.rb
67
73
  - with_model.gemspec
@@ -70,7 +76,6 @@ licenses:
70
76
  - MIT
71
77
  metadata:
72
78
  rubygems_mfa_required: 'true'
73
- post_install_message:
74
79
  rdoc_options: []
75
80
  require_paths:
76
81
  - lib
@@ -78,15 +83,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
83
  requirements:
79
84
  - - ">="
80
85
  - !ruby/object:Gem::Version
81
- version: '2.7'
86
+ version: '3.3'
82
87
  required_rubygems_version: !ruby/object:Gem::Requirement
83
88
  requirements:
84
89
  - - ">="
85
90
  - !ruby/object:Gem::Version
86
91
  version: '0'
87
92
  requirements: []
88
- rubygems_version: 3.4.19
89
- signing_key:
93
+ rubygems_version: 4.0.16
90
94
  specification_version: 4
91
95
  summary: Dynamically build a model within an RSpec context
92
96
  test_files: []
data/.rubocop.yml DELETED
@@ -1,33 +0,0 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
- require:
4
- - rubocop-rake
5
- - rubocop-rspec
6
- - rubocop-minitest
7
-
8
- AllCops:
9
- NewCops: enable
10
- TargetRubyVersion: 2.7
11
- Exclude:
12
- - 'bin/**/*'
13
- - 'vendor/bundle/**/*'
14
-
15
- Metrics/BlockLength:
16
- Exclude:
17
- - 'spec/**/*'
18
- - 'with_model.gemspec'
19
-
20
- Bundler/OrderedGems:
21
- Enabled: false
22
-
23
- Bundler/DuplicatedGem:
24
- Enabled: false
25
-
26
- RSpec/Be:
27
- Enabled: false
28
-
29
- RSpec/BeforeAfterAll:
30
- Enabled: false
31
-
32
- Style/Documentation:
33
- Enabled: false
data/.rubocop_todo.yml DELETED
@@ -1,78 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2020-11-22 01:30:26 UTC using RuboCop version 1.3.1.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 6
10
- # Configuration parameters: Prefixes.
11
- # Prefixes: when, with, without
12
- RSpec/ContextWording:
13
- Exclude:
14
- - 'spec/active_record_behaviors_spec.rb'
15
- - 'spec/with_model_spec.rb'
16
-
17
- # Offense count: 6
18
- # Configuration parameters: IgnoredMetadata.
19
- RSpec/DescribeClass:
20
- Exclude:
21
- - 'spec/active_record_behaviors_spec.rb'
22
- - 'spec/readme_spec.rb'
23
- - 'spec/with_model_spec.rb'
24
-
25
- # Offense count: 5
26
- # Configuration parameters: Max.
27
- RSpec/ExampleLength:
28
- Exclude:
29
- - 'spec/active_record_behaviors_spec.rb'
30
- - 'spec/readme_spec.rb'
31
- - 'spec/with_model_spec.rb'
32
-
33
- # Offense count: 7
34
- # Configuration parameters: AssignmentOnly.
35
- RSpec/InstanceVariable:
36
- Exclude:
37
- - 'spec/active_record_behaviors_spec.rb'
38
-
39
- # Offense count: 2
40
- RSpec/LeakyConstantDeclaration:
41
- Exclude:
42
- - 'spec/readme_spec.rb'
43
- - 'spec/with_model_spec.rb'
44
-
45
- # Offense count: 2
46
- # Configuration parameters: .
47
- # SupportedStyles: have_received, receive
48
- RSpec/MessageSpies:
49
- EnforcedStyle: receive
50
-
51
- # Offense count: 1
52
- RSpec/MultipleDescribes:
53
- Exclude:
54
- - 'spec/readme_spec.rb'
55
-
56
- # Offense count: 13
57
- RSpec/MultipleExpectations:
58
- Max: 5
59
-
60
- # Offense count: 4
61
- # Configuration parameters: IgnoreSharedExamples.
62
- RSpec/NamedSubject:
63
- Exclude:
64
- - 'spec/with_model_spec.rb'
65
-
66
- # Offense count: 2
67
- RSpec/NestedGroups:
68
- Max: 4
69
-
70
- # Offense count: 4
71
- RSpec/RepeatedExample:
72
- Exclude:
73
- - 'spec/with_model_spec.rb'
74
-
75
- # Offense count: 2
76
- RSpec/SubjectStub:
77
- Exclude:
78
- - 'spec/with_model_spec.rb'
data/spec/.rubocop.yml DELETED
@@ -1,5 +0,0 @@
1
- inherit_from:
2
- - ../.rubocop.yml
3
-
4
- Lint/ConstantDefinitionInBlock:
5
- Enabled: false