relation 0.3.7 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,4 @@
1
- # rubocop: disable all
2
-
3
1
  module ModRelation
4
- class Engine < Rails::Engine
5
- isolate_namespace ModRelation
6
-
7
- # # https://github.com/rails/rails/issues/22261
8
- # initializer :append_migrations do |app|
9
- # config.paths['db/migrate'].expanded.each do |path|
10
- # app.config.paths['db/migrate'] << path
11
- # ActiveRecord::Migrator.migrations_paths << path
12
- # end
13
- # end
14
-
15
- # # https://github.com/rails/rails/issues/22261
16
- # module ActiveRecord
17
- # #module ActiveRecord::Current
18
- # class Schema < Migration
19
- # def migrations_paths
20
- # (ActiveRecord::Migrator.migrations_paths +
21
- # Rails.application.paths['db/migrate'].to_a).uniq
22
- # end
23
- # end
24
- # end
2
+ class Engine < ::Rails::Engine
25
3
  end
26
4
  end
@@ -1,12 +1,16 @@
1
1
  # rubocop: disable all
2
2
 
3
3
  module ModRelation
4
- VERSION = '0.3.7' # 2020-07-14
5
- # VERSION = '0.3.6' # 2020-04-27
6
- # VERSION = '0.3.5' # 2020-03-03
7
- # VERSION = '0.3.4' # 2019-10-04
8
- # VERSION = '0.3.3' # 2019-03-23
9
- # VERSION = '0.3.2' # 2019-03-05
10
- # VERSION = '0.3.1' # 2018-08-05
11
- # VERSION = '0.3.0' #
4
+ VERSION = "0.4.2" # 2023-01-19
5
+ # VERSION = "0.4.1" # 2023-01-18
6
+ # VERSION = "0.4.0" # 2023-01-12
7
+ # VERSION = "0.3.8" # 2021-06-22
8
+ # VERSION = "0.3.7" # 2020-07-14
9
+ # VERSION = "0.3.6" # 2020-04-27
10
+ # VERSION = "0.3.5" # 2020-03-03
11
+ # VERSION = "0.3.4" # 2019-10-04
12
+ # VERSION = "0.3.3" # 2019-03-23
13
+ # VERSION = "0.3.2" # 2019-03-05
14
+ # VERSION = "0.3.1" # 2018-08-05
15
+ # VERSION = "0.3.0" #
12
16
  end
data/lib/relation.rb CHANGED
@@ -1,6 +1,3 @@
1
- # rubocop: disable all
2
-
3
- require 'relation/engine.rb'
4
- require 'models/relation.rb'
5
- require 'models/relation_ext.rb'
6
- require 'models/dangling.rb'
1
+ require "models/relation"
2
+ require "models/relation_ext"
3
+ require "models/dangling"
data/relation.gemspec CHANGED
@@ -1,33 +1,29 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
- require 'relation/version'
1
+ require_relative "lib/relation/version"
3
2
 
4
3
  Gem::Specification.new do |s|
5
- s.name = 'relation'
6
- s.version = ModRelation::VERSION
7
- s.summary = <<-'END'
8
- Provides a simple directed relationship between active_record models.
4
+ s.name = "relation"
5
+ s.version = ModRelation::VERSION
6
+ s.summary = <<-'END'
7
+ Rails gem adding relationships between ActiveRecord models.
9
8
  END
10
9
  s.description = <<-'END'
11
10
  A Rails gem that adds simple support for organizing ActiveRecord models.
11
+ Relationships are stored in one additional database table.
12
12
  END
13
- s.authors = ['Dittmar Krall']
14
- s.email = ['dittmar.krall@matique.de']
15
- s.homepage = 'https://github.com/matique/relation'
13
+ s.authors = ["Dittmar Krall"]
14
+ s.email = ["dittmar.krall@matiq.com"]
15
+ s.homepage = "https://matiq.com"
16
+ s.license = "MIT"
17
+ s.platform = Gem::Platform::RUBY
16
18
 
17
- s.license = 'MIT'
18
- s.platform = Gem::Platform::RUBY
19
+ s.metadata["source_code_uri"] = "https://github.com/matique/relation"
19
20
 
20
- s.files = `git ls-files`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- s.test_files = `git ls-files -- {test,features}/*`.split("\n")
23
- s.require_paths = ['lib', 'app']
21
+ s.files = `git ls-files`.split("\n")
22
+ s.require_paths = ["lib", "app"]
24
23
 
25
- s.add_dependency 'activerecord', '~>6'
26
-
27
- s.add_development_dependency 'bundler', '~>1'
28
- s.add_development_dependency 'rake', '~>13'
29
- s.add_development_dependency 'appraisal', '~>2'
30
-
31
- s.add_development_dependency 'minitest', '~>5'
32
- s.add_development_dependency 'sqlite3', '~>1'
24
+ s.add_development_dependency "bundler"
25
+ s.add_development_dependency "combustion"
26
+ s.add_development_dependency "minitest"
27
+ s.add_development_dependency "rake"
28
+ s.add_development_dependency "sqlite3"
33
29
  end
@@ -1,40 +1,35 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  describe Relation do
4
- let(:user) { User.create! name: 'user' }
5
- let(:user2) { User.create! name: 'user2' }
6
- let(:order) { Order.create! name: 'order' }
7
- let(:order2) { Order.create! name: 'order2' }
4
+ let(:user) { User.create! email: "info@sample.com" }
5
+ let(:user2) { User.create! email: "info2@sample.com" }
6
+ let(:order) { Order.create! name: "order" }
7
+ let(:order2) { Order.create! name: "order2" }
8
8
 
9
9
  def setup
10
- DB.setup
11
-
12
- Relation.add user, order
10
+ Relation.delete_all
11
+ Relation.add user, order
13
12
  Relation.add user2, order
14
13
  Relation.add user2, order2
15
14
  end
16
15
 
17
- def teardown
18
- DB.teardown
19
- end
20
-
21
16
  it "test remove dangling #1" do
22
- hsh = { 'User' => [user.id] }
23
- assert_difference('Relation.count', -1) do
17
+ hsh = {"User" => [user.id]}
18
+ assert_difference("Relation.count", -1) do
24
19
  Relation.remove_dangling(hsh)
25
20
  end
26
21
  end
27
22
 
28
23
  it "test remove dangling #2" do
29
- hsh = { 'User' => [user2.id] }
30
- assert_difference('Relation.count', -2) do
24
+ hsh = {"User" => [user2.id]}
25
+ assert_difference("Relation.count", -2) do
31
26
  Relation.remove_dangling(hsh)
32
27
  end
33
28
  end
34
29
 
35
30
  it "test remove dangling #3" do
36
- hsh = { 'Order' => [order.id] }
37
- assert_difference('Relation.count', -2) do
31
+ hsh = {"Order" => [order.id]}
32
+ assert_difference("Relation.count", -2) do
38
33
  Relation.remove_dangling(hsh)
39
34
  end
40
35
  end
@@ -42,12 +37,11 @@ describe Relation do
42
37
  it "test dangling" do
43
38
  assert_equal({}, Relation.dangling)
44
39
  user.destroy
45
- assert_equal({"User"=>[user.id]}, Relation.dangling)
40
+ assert_equal({"User" => [user.id]}, Relation.dangling)
46
41
  user2.destroy
47
- assert_equal({"User"=>[user.id, user2.id]}, Relation.dangling)
42
+ assert_equal({"User" => [user.id, user2.id]}, Relation.dangling)
48
43
  order.destroy
49
- assert_equal({"User"=>[user.id, user2.id].sort, "Order"=>[order.id]},
50
- Relation.dangling)
44
+ assert_equal({"User" => [user.id, user2.id].sort, "Order" => [order.id]},
45
+ Relation.dangling)
51
46
  end
52
-
53
47
  end
@@ -0,0 +1,2 @@
1
+ class Order < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveRecord::Schema.define(version: 202208) do
4
+ create_table :relations, force: true, id: false do |t|
5
+ t.string :name
6
+ t.references :from, null: false
7
+ t.references :to, null: false
8
+ t.timestamps
9
+
10
+ t.index :name
11
+ end
12
+
13
+ create_table "orders", force: true do |t|
14
+ t.string :name
15
+ t.string :category
16
+ t.text :bag
17
+
18
+ t.datetime "created_at", null: false
19
+ t.datetime "updated_at", null: false
20
+ end
21
+
22
+ create_table "users", force: true do |t|
23
+ t.string :email
24
+
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
27
+ end
28
+ end
@@ -1,63 +1,56 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  describe Relation do
4
- let(:user) { User.create! name: 'user' }
5
- let(:user2) { User.create! name: 'user2' }
6
- let(:order) { Order.create! name: 'order' }
7
- let(:order2) { Order.create! name: 'order2' }
4
+ let(:user) { User.create! email: "info@sample.com" }
5
+ let(:user2) { User.create! email: "info2@sample.com" }
6
+ let(:order) { Order.create! name: "order" }
7
+ let(:order2) { Order.create! name: "order2" }
8
8
 
9
9
  def setup
10
- DB.setup
11
-
12
- Relation.add user, order
10
+ Relation.add user, order
13
11
  Relation.add user2, order
14
12
  Relation.add user2, order2
15
13
  end
16
14
 
17
- def teardown
18
- DB.teardown
19
- end
20
-
21
15
  it "should add a connection" do
22
- assert_difference('Relation.count') do
16
+ assert_difference("Relation.count") do
23
17
  Relation.add user2, user
24
18
  end
25
19
  end
26
20
 
27
21
  it "should delete a connection" do
28
22
  Relation.add user2, user
29
- assert_difference('Relation.count', -1) do
23
+ assert_difference("Relation.count", -1) do
30
24
  Relation.delete user2, user
31
25
  end
32
26
  end
33
27
 
34
28
  it "should return references (using class name)" do
35
- arr = Relation.references(user, 'Order')
29
+ arr = Relation.references(user, "Order")
36
30
  assert_equal [order].sort, arr.sort
37
31
 
38
- arr = Relation.references(user2, 'Order')
32
+ arr = Relation.references(user2, "Order")
39
33
  assert_equal [order, order2].sort, arr.sort
40
34
  end
41
35
 
42
36
  it "should return followers (using class name)" do
43
- arr = Relation.followers('User', order)
37
+ arr = Relation.followers("User", order)
44
38
  assert_equal [user, user2].sort, arr.sort
45
39
 
46
- arr = Relation.followers('User', order2)
40
+ arr = Relation.followers("User", order2)
47
41
  assert_equal [user2].sort, arr.sort
48
42
  end
49
43
 
50
44
  it "should not add twice the same connection" do
51
- assert_difference('Relation.count') do
45
+ assert_difference("Relation.count") do
52
46
  Relation.add user2, user
53
47
  Relation.add user2, user
54
48
  end
55
49
  end
56
50
 
57
51
  it "should handle unexistent connection" do
58
- assert_difference('Relation.count', 0) do
52
+ assert_difference("Relation.count", 0) do
59
53
  Relation.delete user2, user
60
54
  end
61
55
  end
62
-
63
56
  end
@@ -1,34 +1,28 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  # testing raw/basic relations
4
4
  describe Relation do
5
- let(:u_id) { User.create!(name: 'user').id }
6
- let(:u2_id) { User.create!(name: 'user2').id }
7
- let(:o_id) { Order.create!(name: 'order').id }
8
- let(:o2_id) { Order.create!(name: 'order2').id }
9
- let(:unknown_id) { 123456 }
5
+ let(:u_id) { User.create!(email: "info@sample.com").id }
6
+ let(:u2_id) { User.create!(email: "info2@sample.com").id }
7
+ let(:o_id) { Order.create!(name: "order").id }
8
+ let(:o2_id) { Order.create!(name: "order2").id }
9
+ let(:unknown_id) { 123456 }
10
10
 
11
11
  def setup
12
- DB.setup
13
-
14
12
  Relation.add_raw :rel, u_id, o_id
15
13
  Relation.add_raw :rel, u2_id, o_id
16
14
  Relation.add_raw :rel, u2_id, o2_id
17
15
  end
18
16
 
19
- def teardown
20
- DB.teardown
21
- end
22
-
23
17
  it "should add a relation" do
24
- assert_difference('Relation.count') do
18
+ assert_difference("Relation.count") do
25
19
  Relation.add_raw :raw, u2_id, u_id
26
20
  end
27
21
  end
28
22
 
29
23
  it "should delete a relation" do
30
24
  Relation.add_raw :raw, u2_id, u_id
31
- assert_difference('Relation.count', -1) do
25
+ assert_difference("Relation.count", -1) do
32
26
  Relation.delete_raw :raw, u2_id, u_id
33
27
  end
34
28
  end
@@ -50,16 +44,15 @@ describe Relation do
50
44
  end
51
45
 
52
46
  it "should not add twice the same connection" do
53
- assert_difference('Relation.count') do
47
+ assert_difference("Relation.count") do
54
48
  Relation.add_raw :rel, u2_id, unknown_id
55
49
  Relation.add_raw :rel, u2_id, unknown_id
56
50
  end
57
51
  end
58
52
 
59
53
  it "should handle unexistent connection" do
60
- assert_difference('Relation.count', 0) do
54
+ assert_difference("Relation.count", 0) do
61
55
  Relation.delete_raw :rel, u2_id, unknown_id
62
56
  end
63
57
  end
64
-
65
58
  end
data/test/test_helper.rb CHANGED
@@ -1,17 +1,16 @@
1
- if ENV['COVERAGE']
2
- require 'simplecov'
1
+ if ENV["COVERAGE"]
2
+ require "simplecov"
3
3
  SimpleCov.start do
4
- add_filter '/test/'
4
+ add_filter "/test/"
5
5
  end
6
6
  end
7
7
 
8
- require 'active_record'
9
- require 'minitest/autorun'
10
-
11
- # Load support files
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
13
-
14
- class Minitest::Test
15
- require 'active_support/testing/assertions'
16
- include ActiveSupport::Testing::Assertions
8
+ require "combustion"
9
+ Combustion.path = "test/internal"
10
+ Combustion.initialize! :active_record do
11
+ config.active_record.yaml_column_permitted_classes = [Symbol, Time, Date]
17
12
  end
13
+
14
+ require "rails/test_help"
15
+ require "minitest/autorun"
16
+ require "minitest/benchmark"
metadata CHANGED
@@ -1,114 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-14 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activerecord
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '6'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '6'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '1'
19
+ version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '1'
26
+ version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rake
28
+ name: combustion
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '13'
33
+ version: '0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '13'
40
+ version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: appraisal
42
+ name: minitest
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - "~>"
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: '2'
47
+ version: '0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: '2'
54
+ version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: minitest
56
+ name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: '5'
61
+ version: '0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '5'
68
+ version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: sqlite3
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - "~>"
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
- version: '1'
75
+ version: '0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - "~>"
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
- version: '1'
97
- description: " A Rails gem that adds simple support for organizing ActiveRecord
98
- models.\n"
82
+ version: '0'
83
+ description: |2
84
+ A Rails gem that adds simple support for organizing ActiveRecord models.
85
+ Relationships are stored in one additional database table.
99
86
  email:
100
- - dittmar.krall@matique.de
87
+ - dittmar.krall@matiq.com
101
88
  executables: []
102
89
  extensions: []
103
90
  extra_rdoc_files: []
104
91
  files:
92
+ - ".github/workflows/rake.yml"
105
93
  - ".gitignore"
106
- - ".rubocop.yml"
107
94
  - ".ruby-gemset"
108
95
  - ".ruby-version"
109
- - ".travis.yml"
110
- - ".watchr"
111
- - Appraisals
112
96
  - Gemfile
113
97
  - Gemfile.lock
114
98
  - MIT-LICENSE
@@ -117,22 +101,24 @@ files:
117
101
  - app/models/dangling.rb
118
102
  - app/models/relation.rb
119
103
  - app/models/relation_ext.rb
120
- - db/migrate/20150810152808_relation.rb
121
- - gemfiles/rails_5.2.gemfile
122
- - gemfiles/rails_6.0.gemfile
104
+ - db/migrate/003_create_relations.rb
123
105
  - lib/relation.rb
124
106
  - lib/relation/engine.rb
125
107
  - lib/relation/version.rb
126
108
  - relation.gemspec
127
109
  - test/dangling_test.rb
110
+ - test/internal/app/models/order.rb
111
+ - test/internal/app/models/user.rb
112
+ - test/internal/config/database.yml
113
+ - test/internal/db/schema.rb
128
114
  - test/relation_ext_test.rb
129
115
  - test/relation_test.rb
130
- - test/support/database.rb
131
116
  - test/test_helper.rb
132
- homepage: https://github.com/matique/relation
117
+ homepage: https://matiq.com
133
118
  licenses:
134
119
  - MIT
135
- metadata: {}
120
+ metadata:
121
+ source_code_uri: https://github.com/matique/relation
136
122
  post_install_message:
137
123
  rdoc_options: []
138
124
  require_paths:
@@ -149,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
135
  - !ruby/object:Gem::Version
150
136
  version: '0'
151
137
  requirements: []
152
- rubygems_version: 3.0.8
138
+ rubygems_version: 3.4.1
153
139
  signing_key:
154
140
  specification_version: 4
155
- summary: Provides a simple directed relationship between active_record models.
141
+ summary: Rails gem adding relationships between ActiveRecord models.
156
142
  test_files: []
data/.rubocop.yml DELETED
@@ -1,8 +0,0 @@
1
- inherit_from:
2
- - ~/configs/.rubocop.yml
3
-
4
- AllCops:
5
- Include:
6
- - 'lib/**/*.rb'
7
- Exclude:
8
- - 'test/**/*'
data/.travis.yml DELETED
@@ -1,43 +0,0 @@
1
- language: ruby
2
- sudo: false
3
-
4
- ## speeding up
5
- #env:
6
- # - TEST_SUITE=units
7
- # - TEST_SUITE=integration
8
- #
9
- #script: "bundle exec rake test:$TEST_SUITE"
10
-
11
- #bundler_args: --without test
12
- bundler_args: --without production
13
- #bundler_args: --without development
14
-
15
- rvm:
16
- - 2.6.6 # 2020-07-14
17
- # - 2.6.5 # 2019-10-29
18
- # - 2.6.4 # 2019-10-04
19
- # - 2.6.3 # 2019-06-21
20
- # - 2.6.1 # 2019-03-05
21
- # - 2.5.1 # 2018-04-27
22
- # - 2.5.0 # 2018-02-22
23
- # - 2.4.1 # tested: working for Rails 5
24
- # - 2.3.1 # tested: working for Rails 5
25
- # - 2.2.7 # tested: working for Rails 5
26
- # - 2.2.0 # tested: failing for Rails 5
27
-
28
- gemfile:
29
- - gemfiles/rails_6.0.gemfile
30
- # - gemfiles/rails_5.2.gemfile
31
- # - gemfiles/rails_5.1.gemfile
32
- # - gemfiles/rails_5.0.gemfile
33
- # - gemfiles/rails_4.gemfile
34
-
35
- notifications:
36
- email: false
37
-
38
- matrix:
39
- # allow_failures:
40
- # - gemfile: gemfiles/rails_5.0.gemfile
41
- # rvm: 2.2.0
42
- # - gemfile: gemfiles/rails_5.1.gemfile
43
- # rvm: 2.2.0