require "spec_helper" require "rails" require "mascot-rails" describe Mascot do context "default configuration" do subject{ Mascot.configuration } it "has sitemap" do expect(subject.sitemap.file_path).to eql(Rails.root.join("app/pages")) end it "has Rails.application as parent engine" do expect(subject.parent_engine).to eql(Rails.application) end it "has routes enabled by default" do expect(subject.routes).to be true end end end describe Mascot::RouteConstraint do let(:sitemap) { Mascot::Sitemap.new(file_path: "spec/pages") } let(:route_constraint) { Mascot::RouteConstraint.new(sitemap) } context "#matches?" do it "returns true if match" do request = double("request", path: "/test") expect(route_constraint.matches?(request)).to be(true) end it "returns false if not match" do request = double("request", path: "/does-not-exist") expect(route_constraint.matches?(request)).to be(false) end end end describe Mascot::ActionControllerContext do subject { Mascot::ActionControllerContext.new(controller: controller, sitemap: sitemap) } let(:sitemap) { Mascot.configuration.sitemap } let(:resource) { sitemap.resources("**.erb*").first } context "#render" do let(:controller) { instance_double("Controller", render: true, _layout: "application") } it "calls render" do expect(controller).to receive(:render).with(inline: resource.body, type: "erb", layout: "flipper", locals: { sitemap: sitemap, current_page: resource, cat: "in-a-hat" }, content_type: resource.mime_type.to_s) subject.render(resource.request_path, locals: {cat: "in-a-hat"}, layout: "flipper") end end end describe Mascot::SitemapController, type: :controller do context "existing templated page" do render_views before { get :show, path: "/time" } let(:resource) { Mascot.configuration.sitemap.find_by_request_path("/time") } it "is status 200" do expect(response.status).to eql(200) end it "renders body" do expect(response.body).to include("