-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
235 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,63 @@ | ||
require "rails_helper" | ||
|
||
describe "fields/has_one/_index", type: :view do | ||
context "without an associated record" do | ||
it "displays nothing" do | ||
has_one = Administrate::Field::HasOne.new( | ||
:product_meta_tag, | ||
build(:product_meta_tag), | ||
:index, | ||
) | ||
let(:product) { create(:product) } | ||
let(:product_path) { polymorphic_path([:admin, product]) } | ||
let(:link) { "<a href=\"#{product_path}\">#{product.name}</a>" } | ||
let(:has_one) do | ||
instance_double( | ||
"Administrate::Field::HasOne", | ||
data: product, | ||
linkable?: true, | ||
display_associated_resource: product.name, | ||
) | ||
end | ||
|
||
render( | ||
partial: "fields/has_one/index", | ||
locals: { field: has_one }, | ||
context "without an associated record" do | ||
let(:has_one) do | ||
instance_double( | ||
"Administrate::Field::HasOne", | ||
linkable?: false, | ||
) | ||
end | ||
|
||
it "displays nothing" do | ||
allow(view).to receive(:administrate_valid_action?).and_return(true) | ||
render_has_one_index | ||
expect(rendered.strip).to eq("") | ||
end | ||
end | ||
|
||
context "with an associated record" do | ||
it "renders a link to the record" do | ||
product = create(:product) | ||
product_path = polymorphic_path([:admin, product]) | ||
has_one = instance_double( | ||
"Administrate::Field::HasOne", | ||
data: product, | ||
linkable?: true, | ||
display_associated_resource: product.name, | ||
) | ||
context "if associated resource has a show route" do | ||
context "and the user has permission to access it" do | ||
it "displays link" do | ||
allow(view).to receive(:administrate_valid_action?).and_return(true) | ||
render_has_one_index | ||
expect(rendered.strip).to include(link) | ||
end | ||
end | ||
|
||
render( | ||
partial: "fields/has_one/index", | ||
locals: { field: has_one, namespace: :admin }, | ||
) | ||
context "and the user does not have permission to access it" do | ||
it "hides link" do | ||
allow(view).to receive(:administrate_valid_action?).and_return(false) | ||
render_has_one_index | ||
expect(rendered.strip).to_not include(link) | ||
end | ||
end | ||
end | ||
|
||
expected = "<a href=\"#{product_path}\">#{product.name}</a>" | ||
expect(rendered.strip).to eq(expected) | ||
context "if associated resource has no show route" do | ||
it "hides link" do | ||
allow(view).to receive(:administrate_valid_action?).and_return(false) | ||
render_has_one_index | ||
expect(rendered.strip).to_not include(link) | ||
end | ||
end | ||
|
||
def render_has_one_index | ||
render( | ||
partial: "fields/has_one/index", | ||
locals: { field: has_one, namespace: :admin }, | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.