rhino_project_core 0.20.0.beta.74 → 0.20.0.beta.77

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: eb6be5c8c0afd98b2b040d187ff2b5aac3fdbcca7253878dda8854fcff664376
4
- data.tar.gz: ffec53e6c49fd8001d9eb2c9699cdd372cb115d45dade303bce2a37c0d8292ae
3
+ metadata.gz: 297bd9f59d6598d9bc3bd82f41865cc1b9de5bbb992d888360d03ae7c80e275d
4
+ data.tar.gz: 4347d328c0ef0b992b3a70d72dddc35597ba7229bb3ef846051f49e668fb7ac6
5
5
  SHA512:
6
- metadata.gz: 427061d1f0f7a8f7dcfba77f2765b53a6f6d0f58d9ca10131bfd2f98b65d2fb98bb3c1b5e1d3b20a50ae607771a2f4e11e26e68dccd781270c06665c9241dcb7
7
- data.tar.gz: 6296a7aeb47b72890c08ecdb41e858cd6dd2ce650fd7ce8eb6370259c5cb77ded40d01c0e624ec45bdb2451b86de7b9058d86f8fbee342a67cab04924ed1f438
6
+ metadata.gz: 91ebdb1e1c10405669f99fbeeb1cc1231a811567ab9149631cb7739e9fad534db432e223c770dd07cae91b71a43f2da4cc2eda618fb2a79b95bd0bded5f82082
7
+ data.tar.gz: 9747f25f00a79e67a297e775ff859c68c6b808ec0d9e325a264c6cde4f3205b3fae141084bc91c8e9deb99f069172123f6492fb41313b9db711d5506ee1c8bd7
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.74"
13
+ PRE = "beta.77"
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.74
4
+ version: 0.20.0.beta.77
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-10 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