Skip to content

Commit 275da30

Browse files
committed
We only support Ruby 3.2 or higher and fix bug in parameters method override
1 parent ace900c commit 275da30

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
},
88
"forwardPorts": [3000],
99
"postCreateCommand": "bundle install && bundle exec appraisal install",
10-
"postStartCommand": "bin/test",
10+
"postStartCommand": "bundle exec rake test",
1111
"remoteUser": "vscode"
1212
}

Gemfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gemspec
77
gem "literal", "~> 1.0"
88

99
gem "standard"
10-
gem "simplecov"
10+
gem "simplecov", require: false, group: :test
1111

1212
gem "rails"
1313
gem "sqlite3"
@@ -21,7 +21,3 @@ gem "appraisal", require: false
2121

2222
# Start debugger with binding.b [https://github.com/ruby/debug]
2323
# gem "debug", ">= 1.0.0"
24-
25-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2.0")
26-
gem "polyfill-data"
27-
end

Rakefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "bundler/setup"
2+
require "bundler/gem_tasks"
3+
4+
desc "Run all tests"
5+
task :test do
6+
sh "bin/test"
7+
end
8+
9+
desc "Run Rails tests"
10+
task :rails_test do
11+
sh "bin/rails_test"
12+
end
13+
14+
task default: [:test, :rails_test]

lib/typed_operation.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2.0")
2-
require "polyfill-data"
3-
end
4-
51
require "literal"
62

73
require "typed_operation/version"

lib/typed_operation/action_policy_auth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def authorized_via(*via, with: nil, to: nil, record: nil, &auth_block)
3434
raise ArgumentError, "authorize_via must be called with a valid param name" unless via.all? { |param| parameters.include?(param) }
3535
@_authorized_via_param = via
3636

37-
action_type_method = "#{action_type}?".to_sym if action_type
37+
action_type_method = :"#{action_type}?" if action_type
3838
# If an method name is provided, use it
3939
policy_method = to || action_type_method || raise(::TypedOperation::InvalidOperationError, "You must provide an action type or policy method name")
4040
@_policy_method = policy_method

lib/typed_operation/operations/parameters.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ module Operations
55
# Method to define parameters for your operation.
66
module Parameters
77
# Override literal `prop` to prevent creating writers (Literal::Data does this by default)
8-
def self.prop(name, type, kind = :keyword, reader: :public, writer: :public, default: nil)
9-
super(name, type, kind, reader:, writer: false, default:)
8+
def prop(name, type, kind = :keyword, reader: :public, writer: :public, default: nil)
9+
if self < ImmutableBase
10+
super(name, type, kind, reader:, default:)
11+
else
12+
super(name, type, kind, reader:, writer: false, default:)
13+
end
1014
end
1115

1216
# Parameter for keyword argument, or a positional argument if you use positional: true

test/test_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require "simplecov"
2+
SimpleCov.start
3+
14
if ENV["NO_RAILS"]
25
puts "Running tests without Rails (ie not running the generator tests)"
36

test/typed_operation/base_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,5 +462,17 @@ def test_can_dup
462462
assert_equal "2", operation2.bar
463463
assert_equal "3", operation2.baz
464464
end
465+
466+
def test_not_frozen
467+
operation = TestOperation.new(foo: "1", bar: "2", baz: "3")
468+
refute operation.frozen?
469+
end
470+
471+
def test_cannot_write_property
472+
operation = TestOperation.new(foo: "1", bar: "2", baz: "3")
473+
assert_raises do
474+
operation.foo = 2
475+
end
476+
end
465477
end
466478
end

0 commit comments

Comments
 (0)