-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix has one class name #1028
Fix has one class name #1028
Conversation
@@ -11,7 +11,7 @@ def associated_resource_grouped_options | |||
end | |||
end | |||
|
|||
def self.permitted_attribute(attr) | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/has_one.rb
Outdated
private | ||
|
||
def resolver | ||
@resolver ||= Administrate::ResourceResolver.new("admin/#{associated_class_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [90/80]
lib/administrate/field/has_one.rb
Outdated
options.fetch(:class_name, attr.to_s.singularize.camelcase) | ||
else | ||
attr | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
lib/administrate/field/has_one.rb
Outdated
end | ||
|
||
def self.permitted_attribute(attr) | ||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surrounding space missing in default value assignment.
lib/administrate/field/has_many.rb
Outdated
@@ -7,8 +7,8 @@ module Field | |||
class HasMany < Associative | |||
DEFAULT_LIMIT = 5 | |||
|
|||
def self.permitted_attribute(attribute) | |||
{ "#{attribute.to_s.singularize}_ids".to_sym => [] } | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/deferred.rb
Outdated
def permitted_attribute(attr) | ||
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | ||
def permitted_attribute(attr, options=nil) | ||
self.options.fetch(:foreign_key, deferred_class.permitted_attribute(attr, self.options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [96/80]
lib/administrate/field/deferred.rb
Outdated
@@ -25,8 +25,8 @@ def searchable? | |||
options.fetch(:searchable, deferred_class.searchable?) | |||
end | |||
|
|||
def permitted_attribute(attr) | |||
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | |||
def permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/belongs_to.rb
Outdated
@@ -3,7 +3,7 @@ | |||
module Administrate | |||
module Field | |||
class BelongsTo < Associative | |||
def self.permitted_attribute(attr) | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/base.rb
Outdated
@@ -24,7 +24,7 @@ def initialize(attribute, data, page, options = {}) | |||
@options = options | |||
end | |||
|
|||
def self.permitted_attribute(attr) | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
@@ -11,7 +11,7 @@ def associated_resource_grouped_options | |||
end | |||
end | |||
|
|||
def self.permitted_attribute(attr) | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/has_one.rb
Outdated
private | ||
|
||
def resolver | ||
@resolver ||= Administrate::ResourceResolver.new("admin/#{associated_class_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [90/80]
lib/administrate/field/has_one.rb
Outdated
options.fetch(:class_name, attr.to_s.singularize.camelcase) | ||
else | ||
attr | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
lib/administrate/field/has_one.rb
Outdated
end | ||
|
||
def self.permitted_attribute(attr) | ||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surrounding space missing in default value assignment.
lib/administrate/field/has_many.rb
Outdated
@@ -7,8 +7,8 @@ module Field | |||
class HasMany < Associative | |||
DEFAULT_LIMIT = 5 | |||
|
|||
def self.permitted_attribute(attribute) | |||
{ "#{attribute.to_s.singularize}_ids".to_sym => [] } | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/deferred.rb
Outdated
def permitted_attribute(attr) | ||
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | ||
def permitted_attribute(attr, options=nil) | ||
self.options.fetch(:foreign_key, deferred_class.permitted_attribute(attr, self.options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [96/80]
lib/administrate/field/deferred.rb
Outdated
@@ -25,8 +25,8 @@ def searchable? | |||
options.fetch(:searchable, deferred_class.searchable?) | |||
end | |||
|
|||
def permitted_attribute(attr) | |||
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | |||
def permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/belongs_to.rb
Outdated
@@ -3,7 +3,7 @@ | |||
module Administrate | |||
module Field | |||
class BelongsTo < Associative | |||
def self.permitted_attribute(attr) | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/base.rb
Outdated
@@ -24,7 +24,7 @@ def initialize(attribute, data, page, options = {}) | |||
@options = options | |||
end | |||
|
|||
def self.permitted_attribute(attr) | |||
def self.permitted_attribute(attr, options=nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Surrounding space missing in default value assignment.
lib/administrate/field/deferred.rb
Outdated
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | ||
def permitted_attribute(attr, _options = nil) | ||
self.options.fetch(:foreign_key, | ||
deferred_class.permitted_attribute(attr, self.options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant self detected.
lib/administrate/field/deferred.rb
Outdated
def permitted_attribute(attr) | ||
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | ||
def permitted_attribute(attr, _options = nil) | ||
self.options.fetch(:foreign_key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant self detected.
lib/administrate/field/deferred.rb
Outdated
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | ||
def permitted_attribute(attr, _options = nil) | ||
self.options.fetch(:foreign_key, | ||
deferred_class.permitted_attribute(attr, self.options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant self detected.
lib/administrate/field/deferred.rb
Outdated
def permitted_attribute(attr) | ||
options.fetch(:foreign_key, deferred_class.permitted_attribute(attr)) | ||
def permitted_attribute(attr, _options = nil) | ||
self.options.fetch(:foreign_key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant self detected.
cbb89ba
to
8df9a57
Compare
spec/lib/fields/has_one_spec.rb
Outdated
field_name = 'seo_meta_tag' | ||
attributes = field.permitted_attribute(field_name) | ||
expect(attributes[:"#{field_name}_attributes"]). | ||
to eq([:meta_title, :meta_description, :id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use %i or %I for an array of symbols.
spec/lib/fields/has_one_spec.rb
Outdated
field = Administrate::Field::Deferred. | ||
new(Administrate::Field::HasOne.with_options(class_name: :product_meta_tag)) | ||
|
||
field_name = 'seo_meta_tag' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
spec/lib/fields/has_one_spec.rb
Outdated
context 'with custom class_name' do | ||
it "returns attributes from correct dashboard" do | ||
field = Administrate::Field::Deferred. | ||
new(Administrate::Field::HasOne.with_options(class_name: :product_meta_tag)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [86/80]
spec/lib/fields/has_one_spec.rb
Outdated
end | ||
|
||
describe ".permitted_attribute" do | ||
context 'with custom class_name' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Added some tests. PR is ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmitry-solomadin This is a great addition to the project. We are using it in one of our projects and it works. Thank you! 👍
Hi @dmitry-solomadin! Thank you for opening this! As I've taken a while to look at it, it's fallen behind a bit. Would you mind rebasing it (it's mostly translations, it seems…)? |
@@ -20,7 +20,7 @@ | |||
deferred.permitted_attribute(:foo) | |||
|
|||
expect(Administrate::Field::String). | |||
to have_received(:permitted_attribute).with(:foo) | |||
to have_received(:permitted_attribute).with(:foo, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the method is providing a default (nil
), is it valuable for us to be providing an empty hash here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, however in that particular case we are testing this method on String field in scope of Deferred attribute, in deferred.rb
the options that we pass are actually initialized with {}
by default
8c61b73
to
4b83819
Compare
@nickcharlton Hey Nick, rebased the branch off latest master, should be good now. |
Looks like some tests on master are failing the same ones are failing on my branch |
Great, thanks! The failures are unrelated to your work, so I'm ignoring them until I get some time on Friday to look at them. I'll merge this now! |
Related issue: #951
Currently, when passing
class_name
option tohas_one
field it does not infer correct class name for the dashboard which results in exception.This PR modifies
has_one
class to useassociative
to get the correct dashboard name.Additionally, it fixes
permitted_attributes
method, which required me to modify the signature and passoptions
fromDeferred
attribute.In scope of this I've also removed old locale keys for
has_one.not_supported
string./r @nickcharlton @tysongach