rhino_project_core 0.20.0.beta.76 → 0.20.0.beta.78

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
  SHA256:
3
- metadata.gz: defa635580bf7c863924f13007e5bb1bda7c77024d2412746ab3e0d92ad767de
4
- data.tar.gz: 71d877e3e97fb4b1b9257a08aadc46616e927e2c3e9b4becb8f407623c87c829
3
+ metadata.gz: 454c08cd487401ea6e20535e8fdb5f3b71737c71822784a25997b396b974b781
4
+ data.tar.gz: 9a489922fb3392de0baeb3dd06b566b6a1c5ae9a70ae3bbddea9270ea6b0b49c
5
5
  SHA512:
6
- metadata.gz: 149c4b8bb9c29a6d0bba5b18db6bb75408fd678e9809cdeb9565327f5c2a8fe4e0146ec64af5434502e779575a4172c8f00c419fec7353821716395e273763e1
7
- data.tar.gz: 675454698618e2d31893f2525bfbfb0fa64174434e75af7f8f8e8d546cd8db58dfcf905bb1b95c6314c7bf237704d0bf894ae55d6faeb4e227174ccca9fd1e11
6
+ metadata.gz: 7f382a73ac01c9f8f361f1266dc8a016d814967eb64711b19c49b0597bb9e2cacfd1f340f7138450ae033d80ac127acdcd5245dd650a480efe18dde60920f80f
7
+ data.tar.gz: ee18f0c39f5b0353d56b684b42380892ebfe9c24247a98514015dd99166f2a8f67029c290745eb0b91bd944e824a55ede7d49ef06792cc670cf1221d602c3823
data/Rakefile CHANGED
@@ -29,6 +29,7 @@ Rake::TestTask.new do |t|
29
29
  t.libs << "test"
30
30
  t.test_files = FileList["test/**/*_test.rb"].exclude("test/system/**/*", "test/dummy/**/*")
31
31
  t.verbose = true
32
+ t.warning = false
32
33
  end
33
34
 
34
35
  task default: :test
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rhino
4
+ module TestCase
5
+ class ModelTest < ActiveSupport::TestCase
6
+ protected
7
+ def assert_required(attribute)
8
+ instance = @model.new
9
+ instance[attribute] = nil
10
+ assert instance.invalid?
11
+ assert_includes instance.errors.messages[attribute], "can't be blank", ":#{attribute} should be required"
12
+ end
13
+
14
+ def assert_not_required(attribute)
15
+ instance = build factory
16
+ instance[attribute] = nil
17
+ assert instance.valid?, ":#{attribute} should not be required, got errors: #{instance.errors.full_messages}"
18
+ end
19
+
20
+ def assert_association_required(association)
21
+ instance = @model.new
22
+ instance.send("#{association}_id=", nil)
23
+ assert instance.invalid?
24
+ assert_includes instance.errors.messages[association], "must exist", ":#{association} should be required"
25
+ end
26
+
27
+ def assert_uniqueness(attribute, scope: nil)
28
+ instance = create factory
29
+ duplicate = build factory, attribute => instance[attribute]
30
+ duplicate.send("#{scope}=", instance.send(scope)) if scope.present?
31
+ assert duplicate.invalid?, "Should be invalid with duplicate #{attribute}"
32
+ assert_includes duplicate.errors.messages[attribute], "has already been taken", ":#{attribute} should be unique"
33
+ end
34
+
35
+ # association_model is a symbol
36
+ def assert_accepts_nested_attributes_for(association_model, association_factory: association_model) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
37
+ association = @model.reflect_on_association(association_model)
38
+
39
+ assert association.present?, "association :#{association_model} not found"
40
+
41
+ key = if association.macro == :belongs_to || association.macro == :has_one
42
+ "#{association_model}_attributes"
43
+ else
44
+ "#{association_model.to_s.pluralize}_attributes"
45
+ end
46
+
47
+ success_checker = if association.macro == :belongs_to || association.macro == :has_one
48
+ ->(instance) { instance.reload.send(association_model).present? }
49
+ else
50
+ ->(instance) { instance.reload.send(association_model).any? }
51
+ end
52
+
53
+ assert @model.new.respond_to?("#{key}="),
54
+ "#{@model} doesn't have a #{key} setter method. Probably there's no `accepts_nested_attributes_for :#{association_model}` in #{@model}" # rubocop:disable Layout/LineLength
55
+ object = if association_factory.is_a?(Proc)
56
+ model_instance = build factory
57
+ association_instance = association_factory.call model_instance
58
+ model_instance.send("#{key}=", association_instance.attributes)
59
+ model_instance
60
+ else
61
+ build factory, { key => build(association_factory).attributes }
62
+ end
63
+ assert object.valid?, "Should be valid after assigning nested model attributes, but got errors: #{object.errors.full_messages}"
64
+ assert object.save, "Should be able to save after assigning nested model attributes, but got errors: #{object.errors.full_messages}"
65
+ assert success_checker.call(object), "Should have a #{association_model} after assigning nested model attributes"
66
+ end
67
+
68
+ def assert_destroy_association_cascade(association_model, association_factory: association_model) # rubocop:disable Metrics/AbcSize
69
+ instance = create factory
70
+ association_instance = if association_factory.is_a?(Proc)
71
+ association_factory.call(instance)
72
+ else
73
+ create association, { @model.to_s.underscore => instance }
74
+ end
75
+ assert instance.reload.send(association_model).any?, "Should have a #{association_model} after creating #{@model}"
76
+ assert instance.destroy, "Should be able to destroy #{@model}"
77
+ assert_not association_instance.class.exists?(association_instance.id), "Should destroy #{association_model} when destroying #{@model}"
78
+ end
79
+
80
+ private
81
+ def factory
82
+ @factory ||= @model.to_s.underscore.to_sym
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "test_case/controller"
4
+ require_relative "test_case/model"
4
5
  require_relative "test_case/override"
5
6
  require_relative "test_case/policy"
6
7
 
data/lib/rhino/version.rb CHANGED
@@ -10,7 +10,7 @@ module Rhino
10
10
  MAJOR = 0
11
11
  MINOR = 20
12
12
  TINY = 0
13
- PRE = "beta.76"
13
+ PRE = "beta.78"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhino_project_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0.beta.76
4
+ version: 0.20.0.beta.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Rosevear
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-11 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -227,6 +227,7 @@ files:
227
227
  - lib/rhino/sieve/search.rb
228
228
  - lib/rhino/test_case.rb
229
229
  - lib/rhino/test_case/controller.rb
230
+ - lib/rhino/test_case/model.rb
230
231
  - lib/rhino/test_case/override.rb
231
232
  - lib/rhino/test_case/policy.rb
232
233
  - lib/rhino/version.rb