Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/subroutine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ def self.include_defaults_in_params?
false
end

def self.inheritable_field_options=(opts)
@inheritable_field_options = opts.map(&:to_sym)
end

def self.inheritable_field_options
@inheritable_field_options ||= %i[mass_assignable field_reader field_writer groups aka]
end

end
3 changes: 1 addition & 2 deletions lib/subroutine/fields/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Fields
class Configuration < ::SimpleDelegator

PROTECTED_GROUP_IDENTIFIERS = %i[all original default].freeze
INHERITABLE_OPTIONS = %i[mass_assignable field_reader field_writer groups aka].freeze
NO_GROUPS = [].freeze

def self.from(field_name, options)
Expand Down Expand Up @@ -61,7 +60,7 @@ def get_default
end

def inheritable_options
config.slice(*INHERITABLE_OPTIONS)
config.slice(*Subroutine.inheritable_field_options)
end

def mass_assignable?
Expand Down
2 changes: 1 addition & 1 deletion lib/subroutine/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Subroutine

MAJOR = 4
MINOR = 1
PATCH = 1
PATCH = 3
PRE = nil

VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
Expand Down
15 changes: 15 additions & 0 deletions test/subroutine/association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,20 @@ def test_find_by_is_used_if_raise_on_miss_is_false
assert_nil op.user
end

def test_inheritable_options_are_inherited_by_child_fields
Subroutine.stubs(:inheritable_field_options).returns(%i[foo bar])
klass = Class.new(OpWithAssociation) do
association :buster, foo: true, bar: false, baz: true
association :mister, polymorphic: true, foo: true, bar: false, baz: true
end

%i[buster_id mister_id mister_type].each do |field_name|
field = klass.field_configurations.fetch(field_name)
assert_equal true, field[:foo]
assert_equal false, field[:bar]
assert_equal false, field.config.key?(:baz)
end
end

end
end