-
-
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
Display helpful message if attribute_name missing #251
Changes from 3 commits
62570b6
52567fd
da3b07c
c71fa38
772774f
58c6017
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ def attributes_for(resource) | |
end | ||
|
||
def attribute_types | ||
dashboard.attribute_types.slice(*attribute_names) | ||
dashboard.attribute_types_for(*attribute_names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's get rid of the splat operator here ( |
||
end | ||
|
||
def ordered_html_class(attr) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,45 @@ | |
end | ||
end | ||
|
||
describe "#attribute_type_for" do | ||
context "for an existing attribute" do | ||
it "returns the attribute field" do | ||
dashboard = CustomerDashboard.new | ||
field = dashboard.attribute_type_for(:name) | ||
expect(field).to eq Administrate::Field::String | ||
end | ||
end | ||
|
||
context "for a non-existent attribute" do | ||
it "raises an exception" do | ||
dashboard = CustomerDashboard.new | ||
expect { dashboard.attribute_type_for(:foo) }. | ||
to raise_error /Attribute foo not in CustomerDashboard/ | ||
end | ||
end | ||
end | ||
|
||
describe "#attribute_types_for" do | ||
context "for existing attributes" do | ||
it "returns the attribute fields" do | ||
dashboard = CustomerDashboard.new | ||
fields = dashboard.attribute_types_for(:name, :email) | ||
expect(fields).to match( | ||
name: Administrate::Field::String, | ||
email: Administrate::Field::Email, | ||
) | ||
end | ||
end | ||
|
||
context "for one non-existent attribute" do | ||
it "raises an exception" do | ||
dashboard = CustomerDashboard.new | ||
expect { dashboard.attribute_types_for(:name, :foo) }. | ||
to raise_error /Attribute foo not in CustomerDashboard/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you feel about extracting a method here? expect { dashboard.attribute_types_for(:name, :foo) }.
to raise_error(message_for("foo", "CustomerDashboard"))
def message_for(attribute, dashboard_class)
"Attribute #{attribute} could not be found in #{dashboard_class}::ATTRIBUTE_TYPES"
end Note: I also slightly changed the wording of the error message in that snippet, I think it reads a bit better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree about the wording. That's what I had originally but the Hound was against it since it's 95 characters long 😆 I'll put it back |
||
end | ||
end | ||
end | ||
|
||
describe "#display_resource" do | ||
it "returns the customer's name" do | ||
customer = double(name: "Example Customer") | ||
|
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.
same here for the splat operator.