activerecord-null 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -10
- data/Rakefile +4 -1
- data/lib/activerecord/null/mimic.rb +7 -1
- data/lib/activerecord/null/version.rb +1 -1
- data/lib/activerecord/null.rb +1 -0
- data/test/activerecord/test_null.rb +62 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61c6b213e7c4c8f5cbeab18700a2eebc46803592fb34b3677ed93da0a6c49c92
|
|
4
|
+
data.tar.gz: 698f74dbdf03af5dbdc7e35111f20a478363c832028258c77cc14fdf0061b8b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e8fd9f3d1c8c130a997e3c66c6560b82e18b2ff782a2772832de7e4344abb59f0a6ef0efcaae67cb2a47dd221076b1113be2a0f520bc0c267a6ecb137c3b7eb
|
|
7
|
+
data.tar.gz: 9848bd89df1f1cb2ded9dcecd27f478aacbac6ed1586f56ecd7b17446b3755bceec6fbef8b0858b58be7996da11617c1d2f056517c0a55a03aff26a79ee483e5
|
data/CHANGELOG.md
CHANGED
|
@@ -5,16 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [0.1.
|
|
8
|
+
## [0.1.3] - 2025-11-18
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
### Changed
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
- Use git trailers to track changelog entries. (d296851)
|
|
13
|
+
- Implement [] method to access attributes with string/symbol keys (1dc4f95)
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
### Removed
|
|
16
|
+
|
|
17
|
+
- CodeClimate access on CI runs. (2dbf5bc)
|
|
18
|
+
|
|
19
|
+
## [0.1.3] - 2025-11-18
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Use git trailers to track changelog entries. (d296851)
|
|
24
|
+
- Implement [] method to access attributes with string/symbol keys (1dc4f95)
|
|
25
|
+
|
|
26
|
+
### Removed
|
|
27
|
+
|
|
28
|
+
- CodeClimate access on CI runs. (2dbf5bc)
|
data/Rakefile
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
require "bundler/gem_tasks"
|
|
4
4
|
require "minitest/test_task"
|
|
5
5
|
|
|
6
|
-
Minitest::TestTask.create
|
|
6
|
+
Minitest::TestTask.create do |t|
|
|
7
|
+
t.test_prelude = 'require "test_helper"'
|
|
8
|
+
end
|
|
7
9
|
|
|
8
10
|
task default: :test
|
|
9
11
|
|
|
@@ -11,4 +13,5 @@ require "reissue/gem"
|
|
|
11
13
|
|
|
12
14
|
Reissue::Task.create :reissue do |task|
|
|
13
15
|
task.version_file = "lib/activerecord/null/version.rb"
|
|
16
|
+
task.fragment = :git
|
|
14
17
|
end
|
|
@@ -35,7 +35,13 @@ module ActiveRecord
|
|
|
35
35
|
|
|
36
36
|
attr_reader :id
|
|
37
37
|
|
|
38
|
-
def [](
|
|
38
|
+
def [](key)
|
|
39
|
+
normalized_key = key.to_sym
|
|
40
|
+
association_names = mimic_model_class.reflect_on_all_associations.map(&:name)
|
|
41
|
+
|
|
42
|
+
return nil if association_names.include?(normalized_key)
|
|
43
|
+
|
|
44
|
+
respond_to?(normalized_key) ? send(normalized_key) : nil
|
|
39
45
|
end
|
|
40
46
|
|
|
41
47
|
def is_a?(klass)
|
data/lib/activerecord/null.rb
CHANGED
|
@@ -124,6 +124,68 @@ class ActiveRecord::TestNull < Minitest::Spec
|
|
|
124
124
|
it "responds to mimic methods" do
|
|
125
125
|
expect(Post.null.respond_to?(:description)).must_equal true
|
|
126
126
|
end
|
|
127
|
+
|
|
128
|
+
describe "bracket access" do
|
|
129
|
+
describe "with attributes" do
|
|
130
|
+
it "accesses attribute with symbol key" do
|
|
131
|
+
expect(User.null[:name]).must_equal "None"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "accesses attribute with string key" do
|
|
135
|
+
expect(User.null["name"]).must_equal "None"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "returns same value for string and symbol keys" do
|
|
139
|
+
expect(User.null[:team_name]).must_equal User.null["team_name"]
|
|
140
|
+
expect(User.null[:team_name]).must_equal "Unknown"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "returns custom attribute values" do
|
|
144
|
+
expect(User.null[:name]).must_equal "None"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "returns static assigned attribute values" do
|
|
148
|
+
expect(User.null[:team_name]).must_equal "Unknown"
|
|
149
|
+
expect(User.null[:other]).must_equal "Unknown"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "returns callable attribute values" do
|
|
153
|
+
expect(Post.null[:description]).must_equal "From the callable!"
|
|
154
|
+
expect(Post.null["description"]).must_equal "From the callable!"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "returns nil for default attributes" do
|
|
158
|
+
expect(User.null[:id]).must_be_nil
|
|
159
|
+
expect(Post.null[:title]).must_be_nil
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
describe "with associations" do
|
|
164
|
+
it "returns nil for belongs_to association" do
|
|
165
|
+
expect(User.null[:business]).must_be_nil
|
|
166
|
+
expect(Post.null[:user]).must_be_nil
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "returns nil for has_many association" do
|
|
170
|
+
expect(User.null[:posts]).must_be_nil
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "still allows dot notation for associations" do
|
|
174
|
+
expect(User.null.business).must_be_instance_of Business::Null
|
|
175
|
+
expect(User.null.posts).must_be_kind_of ActiveRecord::Relation
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
describe "with non-existent keys" do
|
|
180
|
+
it "returns nil for unknown symbol key" do
|
|
181
|
+
expect(User.null[:nonexistent]).must_be_nil
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "returns nil for unknown string key" do
|
|
185
|
+
expect(User.null["nonexistent"]).must_be_nil
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
127
189
|
end
|
|
128
190
|
|
|
129
191
|
describe "Parent class object" do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-null
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jim Gay
|
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
62
62
|
- !ruby/object:Gem::Version
|
|
63
63
|
version: '0'
|
|
64
64
|
requirements: []
|
|
65
|
-
rubygems_version: 3.
|
|
65
|
+
rubygems_version: 3.7.2
|
|
66
66
|
specification_version: 4
|
|
67
67
|
summary: Null Objects for ActiveRecord
|
|
68
68
|
test_files: []
|