Sha256: 0c2da2f7e3adcc347437a8a381b80f654a17827952d19c15899715225cc1e43f

Contents?: true

Size: 1.77 KB

Versions: 18

Compression:

Stored size: 1.77 KB

Contents

require 'rails_helper'

RSpec.describe ActiveAdmin::Views::Pages::Form do
  describe "#title" do
    let!(:application){ ActiveAdmin::Application.new }
    let(:namespace){ ActiveAdmin::Namespace.new(application, "Admin") }
    let!(:http_params){ { controller: "UsersController", action: "edit" } }
    let!(:params) { ActionController::Parameters.new(http_params) }

    let(:helpers) do
      helpers = mock_action_view
      allow(helpers).to receive(:active_admin_config).and_return(namespace.register(Post))
      allow(helpers).to receive(:params).and_return(params)
      helpers
    end

    let(:arbre_context) do
      OpenStruct.new(params: params, helpers: helpers, assigns: {})
    end

    context "when :title is set" do
      it "should show the set page title" do

        page = ActiveAdmin::Views::Pages::Form.new(arbre_context)
        expect(page).to receive(:resource)
        expect(page).to receive(:form_presenter).twice.and_return({ title: "My Page Title" })
        expect(page.title).to eq "My Page Title"
      end
    end

    context "when page_title is assigned" do
      it "should show the set page title" do
        arbre_context.assigns[:page_title] = "My Page Title"
        page = ActiveAdmin::Views::Pages::Form.new(arbre_context)
        expect(page.title).to eq "My Page Title"
      end
    end

    context "when page_title is not assigned" do
      {
        "new" => "New Post",
        "create" => "New Post",
        "edit" => "Edit Post",
        "update" => "Edit Post"
      }.each do |action, title|
        it "should show the correct I18n text on the #{action} action" do
          params[:action] = action
          page = ActiveAdmin::Views::Pages::Form.new(arbre_context)
          expect(page.title).to eq title
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
activeadmin-rb-1.6.0 spec/unit/views/pages/form_spec.rb
activeadmin-rb-1.5.2 spec/unit/views/pages/form_spec.rb
activeadmin-rb-1.5.1 spec/unit/views/pages/form_spec.rb
activeadmin-rb-1.5.0 spec/unit/views/pages/form_spec.rb
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/views/pages/form_spec.rb
activeadmin-rb-1.4.0 spec/unit/views/pages/form_spec.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/views/pages/form_spec.rb
activeadmin-1.3.1 spec/unit/views/pages/form_spec.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/views/pages/form_spec.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/views/pages/form_spec.rb
activeadmin-1.3.0 spec/unit/views/pages/form_spec.rb
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/views/pages/form_spec.rb
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/views/pages/form_spec.rb
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/views/pages/form_spec.rb
activeadmin-1.2.1 spec/unit/views/pages/form_spec.rb
activeadmin-1.2.0 spec/unit/views/pages/form_spec.rb
activeadmin-1.1.0 spec/unit/views/pages/form_spec.rb
activeadmin-1.0.0 spec/unit/views/pages/form_spec.rb