spec/unit/auto_link_spec.rb in activeadmin-rb-1.4.0 vs spec/unit/auto_link_spec.rb in activeadmin-rb-1.5.0
- old
+ new
@@ -2,30 +2,40 @@
require 'active_admin/view_helpers/active_admin_application_helper'
require 'active_admin/view_helpers/auto_link_helper'
require 'active_admin/view_helpers/display_helper'
require 'active_admin/view_helpers/method_or_proc_helper'
-RSpec.describe "auto linking resources", type: :view do
- include ActiveAdmin::ViewHelpers::ActiveAdminApplicationHelper
- include ActiveAdmin::ViewHelpers::AutoLinkHelper
- include ActiveAdmin::ViewHelpers::DisplayHelper
- include MethodOrProcHelper
+RSpec.describe "#auto_link" do
+ let(:view_klass) do
+ Class.new(ActionView::Base) do
+ include ActiveAdmin::ViewHelpers::ActiveAdminApplicationHelper
+ include ActiveAdmin::ViewHelpers::AutoLinkHelper
+ include ActiveAdmin::ViewHelpers::DisplayHelper
+ include MethodOrProcHelper
+ end
+ end
+ let(:view) { mock_action_view(view_klass) }
+
+ let(:linked_post) { view.auto_link(post) }
+
let(:active_admin_namespace){ ActiveAdmin.application.namespace(:admin) }
let(:post){ Post.create! title: "Hello World" }
before do
- allow(self).to receive(:authorized?).and_return(true)
+ allow(view).to receive(:authorized?).and_return(true)
+ allow(view).to receive(:active_admin_namespace).and_return(active_admin_namespace)
+ allow(view).to receive(:url_options).and_return({})
end
context "when the resource is not registered" do
before do
load_resources {}
end
it "should return the display name of the object" do
- expect(auto_link(post)).to eq "Hello World"
+ expect(linked_post).to eq "Hello World"
end
end
context "when the resource is registered" do
before do
@@ -33,28 +43,28 @@
active_admin_namespace.register Post
end
end
it "should return a link with the display name of the object" do
- expect(auto_link(post)).to \
+ expect(linked_post).to \
match(%r{<a href="/admin/posts/\d+">Hello World</a>})
end
it "should keep locale in the url if present" do
- expect(self).to receive(:url_options).and_return(locale: 'en')
+ expect(view).to receive(:url_options).and_return(locale: 'en')
- expect(auto_link(post)).to \
+ expect(linked_post).to \
match(%r{<a href="/admin/posts/\d+\?locale=en">Hello World</a>})
end
context "but the user doesn't have access" do
before do
- allow(self).to receive(:authorized?).and_return(false)
+ allow(view).to receive(:authorized?).and_return(false)
end
it "should return the display name of the object" do
- expect(auto_link(post)).to eq "Hello World"
+ expect(linked_post).to eq "Hello World"
end
end
end
context "when the resource is registered with the show action disabled" do
@@ -63,18 +73,18 @@
active_admin_namespace.register(Post) { actions :all, except: :show }
end
end
it "should fallback to edit" do
- expect(auto_link(post)).to \
+ expect(linked_post).to \
match(%r{<a href="/admin/posts/\d+/edit">Hello World</a>})
end
it "should keep locale in the url if present" do
- expect(self).to receive(:url_options).and_return(locale: 'en')
+ expect(view).to receive(:url_options).and_return(locale: 'en')
- expect(auto_link(post)).to \
+ expect(linked_post).to \
match(%r{<a href="/admin/posts/\d+/edit\?locale=en">Hello World</a>})
end
end
context "when the resource is registered with the show & edit actions disabled" do
@@ -84,10 +94,10 @@
actions :all, except: [:show, :edit]
end
end
it "should return the display name of the object" do
- expect(auto_link(post)).to eq "Hello World"
+ expect(linked_post).to eq "Hello World"
end
end
end
end