relation 0.3.8 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,17 @@
1
1
  # rubocop: disable all
2
2
 
3
3
  module ModRelation
4
- VERSION = '0.3.8' # 2021-06-22
5
- # VERSION = '0.3.7' # 2020-07-14
6
- # VERSION = '0.3.6' # 2020-04-27
7
- # VERSION = '0.3.5' # 2020-03-03
8
- # VERSION = '0.3.4' # 2019-10-04
9
- # VERSION = '0.3.3' # 2019-03-23
10
- # VERSION = '0.3.2' # 2019-03-05
11
- # VERSION = '0.3.1' # 2018-08-05
12
- # VERSION = '0.3.0' #
4
+ VERSION = "0.4.3" # 2023-04-16
5
+ # VERSION = "0.4.2" # 2023-01-19
6
+ # VERSION = "0.4.1" # 2023-01-18
7
+ # VERSION = "0.4.0" # 2023-01-12
8
+ # VERSION = "0.3.8" # 2021-06-22
9
+ # VERSION = "0.3.7" # 2020-07-14
10
+ # VERSION = "0.3.6" # 2020-04-27
11
+ # VERSION = "0.3.5" # 2020-03-03
12
+ # VERSION = "0.3.4" # 2019-10-04
13
+ # VERSION = "0.3.3" # 2019-03-23
14
+ # VERSION = "0.3.2" # 2019-03-05
15
+ # VERSION = "0.3.1" # 2018-08-05
16
+ # VERSION = "0.3.0" #
13
17
  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,34 +1,27 @@
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
- s.description = <<-'END'
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'
16
- s.license = 'MIT'
17
- s.platform = Gem::Platform::RUBY
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
18
18
 
19
- s.metadata['source_code_uri'] = 'https://github.com/matique/relation'
19
+ s.metadata["source_code_uri"] = "https://github.com/matique/relation"
20
20
 
21
- s.files = `git ls-files`.split("\n")
22
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
- s.test_files = `git ls-files -- {test,features}/*`.split("\n")
24
- s.require_paths = ['lib', 'app']
21
+ s.files = `git ls-files`.split("\n")
22
+ s.require_paths = ["lib", "app"]
25
23
 
26
- s.add_dependency 'activerecord'
27
-
28
- s.add_development_dependency 'bundler'
29
- s.add_development_dependency 'rake'
30
- s.add_development_dependency 'appraisal'
31
-
32
- s.add_development_dependency 'minitest'
33
- s.add_development_dependency 'sqlite3'
24
+ s.add_development_dependency "combustion"
25
+ s.add_development_dependency "minitest"
26
+ s.add_development_dependency "sqlite3"
34
27
  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,59 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-22 00:00:00.000000000 Z
11
+ date: 2023-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activerecord
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: appraisal
14
+ name: combustion
57
15
  requirement: !ruby/object:Gem::Requirement
58
16
  requirements:
59
17
  - - ">="
@@ -94,21 +52,19 @@ dependencies:
94
52
  - - ">="
95
53
  - !ruby/object:Gem::Version
96
54
  version: '0'
97
- description: " A Rails gem that adds simple support for organizing ActiveRecord
98
- models.\n"
55
+ description: |2
56
+ A Rails gem that adds simple support for organizing ActiveRecord models.
57
+ Relationships are stored in one additional database table.
99
58
  email:
100
- - dittmar.krall@matique.de
59
+ - dittmar.krall@matiq.com
101
60
  executables: []
102
61
  extensions: []
103
62
  extra_rdoc_files: []
104
63
  files:
105
64
  - ".github/workflows/rake.yml"
106
65
  - ".gitignore"
107
- - ".rubocop.yml"
108
66
  - ".ruby-gemset"
109
67
  - ".ruby-version"
110
- - ".watchr"
111
- - Appraisals
112
68
  - Gemfile
113
69
  - Gemfile.lock
114
70
  - MIT-LICENSE
@@ -117,19 +73,20 @@ files:
117
73
  - app/models/dangling.rb
118
74
  - app/models/relation.rb
119
75
  - app/models/relation_ext.rb
120
- - db/migrate/20150810152808_relation.rb
121
- - gemfiles/rails_6.0.gemfile
122
- - gemfiles/rails_6.1.gemfile
76
+ - db/migrate/003_create_relations.rb
123
77
  - lib/relation.rb
124
78
  - lib/relation/engine.rb
125
79
  - lib/relation/version.rb
126
80
  - relation.gemspec
127
81
  - test/dangling_test.rb
82
+ - test/internal/app/models/order.rb
83
+ - test/internal/app/models/user.rb
84
+ - test/internal/config/database.yml
85
+ - test/internal/db/schema.rb
128
86
  - test/relation_ext_test.rb
129
87
  - test/relation_test.rb
130
- - test/support/database.rb
131
88
  - test/test_helper.rb
132
- homepage: https://github.com/matique/relation
89
+ homepage: https://matiq.com
133
90
  licenses:
134
91
  - MIT
135
92
  metadata:
@@ -150,8 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
107
  - !ruby/object:Gem::Version
151
108
  version: '0'
152
109
  requirements: []
153
- rubygems_version: 3.2.6
110
+ rubygems_version: 3.4.10
154
111
  signing_key:
155
112
  specification_version: 4
156
- summary: Provides a simple directed relationship between active_record models.
113
+ summary: Rails gem adding relationships between ActiveRecord models.
157
114
  test_files: []
data/.rubocop.yml DELETED
@@ -1,9 +0,0 @@
1
- inherit_from:
2
- - ~/configs/.rubocop.yml
3
-
4
- AllCops:
5
- NewCops: enable
6
- Include:
7
- - 'lib/**/*.rb'
8
- Exclude:
9
- - 'test/**/*'
data/.watchr DELETED
@@ -1,59 +0,0 @@
1
- TESTING = %w[test]
2
- HH = '#' * 22 unless defined?(HH)
3
- H = '#' * 5 unless defined?(H)
4
-
5
- def usage
6
- puts <<-EOS
7
- Ctrl-\\ or ctrl-4 Running all tests
8
- Ctrl-C Exit
9
- EOS
10
- end
11
-
12
- def run(cmd)
13
- puts "#{HH} #{Time.now} #{HH}"
14
- puts "#{H} #{cmd}"
15
- system "/usr/bin/time --format '#{HH} Elapsed time %E' #{cmd}"
16
- end
17
-
18
- def run_it(type, file)
19
- case type
20
- when 'test'; run %(bundle exec ruby -I test #{file})
21
- # when 'spec'; run %(rspec -X #{file})
22
- else; puts "#{H} unknown type: #{type}, file: #{file}"
23
- end
24
- end
25
-
26
- def run_all_tests
27
- puts "\n#{HH} Running all tests #{HH}\n"
28
- TESTING.each { |dir| run "bundle exec rake #{dir}" if File.exist?(dir) }
29
- end
30
-
31
- def run_matching_files(base)
32
- base = base.split('_').first
33
- TESTING.each { |type|
34
- files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
35
- run_it type, files.join(' ') unless files.empty?
36
- }
37
- end
38
-
39
- TESTING.each { |type|
40
- watch("#{type}/#{type}_helper\.rb") { run_all_tests }
41
- watch('lib/.*\.rb') { run_all_tests }
42
- watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
43
- watch("#{type}/data/(.*)\.rb") { |match|
44
- m1 = match[1]
45
- run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
46
- }
47
- }
48
-
49
- %w[rb erb haml slim].each { |type|
50
- watch(".*/(.*)\.#{type}") { |match|
51
- run_matching_files(match[1])
52
- }
53
- }
54
-
55
- # Ctrl-\ or ctrl-4
56
- Signal.trap('QUIT') { run_all_tests }
57
- # Ctrl-C
58
- Signal.trap('INT') { abort("Interrupted\n") }
59
- usage
data/Appraisals DELETED
@@ -1,19 +0,0 @@
1
- appraise 'rails-6.1' do
2
- gem 'rails', '~> 6.1'
3
- end
4
-
5
- appraise 'rails-6.0' do
6
- gem 'rails', '~> 6.0'
7
- end
8
-
9
- #appraise 'rails-5.2' do
10
- # gem 'rails', '~> 5.2.0'
11
- #end
12
- #
13
- #appraise 'rails-5.0' do
14
- # gem 'rails', '~> 5.0.0'
15
- #end
16
- #
17
- #appraise 'rails-5.1' do
18
- # gem 'rails', '~> 5.1'
19
- #end
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 6.0"
6
-
7
- group :test do
8
- gem "observr"
9
- gem "rubocop", require: false
10
- gem "simplecov", require: false
11
- end
12
-
13
- gemspec path: "../"
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 6.1"
6
-
7
- group :test do
8
- gem "observr"
9
- gem "rubocop", require: false
10
- gem "simplecov", require: false
11
- end
12
-
13
- gemspec path: "../"