diff --git a/.rubocop.yml b/.rubocop.yml index ffa694f74a..6921c3e008 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -105,6 +105,10 @@ Rails/SkipsModelValidations: Exclude: - 'db/migrate/*' +Capybara/FeatureMethods: + Exclude: + - 'spec/features/**_spec.rb' + # Allow the use of 'and' 'or' in control structures. Style/AndOr: EnforcedStyle: conditionals diff --git a/publify_core/app/views/admin/themes/index.html.erb b/publify_core/app/views/admin/themes/index.html.erb index 45d465edbf..aa8f828054 100644 --- a/publify_core/app/views/admin/themes/index.html.erb +++ b/publify_core/app/views/admin/themes/index.html.erb @@ -16,10 +16,10 @@ <% else %>
-

<%= link_to(theme.name, switch_url, title: t('.use_this_theme')) %>

- <%= link_to(image_tag(preview_url, class: 'img-thumbnail'), switch_url, title: t('.use_this_theme')) %> +

<%= theme.name %>

+ <%= image_tag(preview_url, class: 'img-thumbnail') %> <%= raw theme.description_html %> -

<%= link_to(t('.use_this_theme'), switch_url, class: 'btn btn-info') %>

+

<%= button_to(t('.use_this_theme'), switch_url, class: 'btn btn-info') %>

<% end %> diff --git a/publify_core/config/routes.rb b/publify_core/config/routes.rb index 3224c1a51a..93ab3ed754 100644 --- a/publify_core/config/routes.rb +++ b/publify_core/config/routes.rb @@ -144,7 +144,7 @@ resources :themes, only: [:index], format: false do collection do get "preview" - get "switchto" + post "switchto" end end diff --git a/publify_core/spec/controllers/admin/themes_controller_spec.rb b/publify_core/spec/controllers/admin/themes_controller_spec.rb index 738ea68c44..50dec48071 100644 --- a/publify_core/spec/controllers/admin/themes_controller_spec.rb +++ b/publify_core/spec/controllers/admin/themes_controller_spec.rb @@ -23,7 +23,7 @@ end it "redirects to :index after the :switchto action" do - get :switchto, params: { theme: "typographic" } + post :switchto, params: { theme: "typographic" } assert_response :redirect, action: "index" end diff --git a/publify_core/spec/rails_helper.rb b/publify_core/spec/rails_helper.rb index 98ed27acd2..1539e9e541 100644 --- a/publify_core/spec/rails_helper.rb +++ b/publify_core/spec/rails_helper.rb @@ -74,6 +74,7 @@ # Test helpers needed for Devise config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::IntegrationHelpers, type: :feature + config.include Devise::Test::IntegrationHelpers, type: :request # Test helpers to check feed contents config.include PublifyCore::TestingSupport::FeedAssertions, type: :view diff --git a/publify_core/spec/requests/admin/themes_spec.rb b/publify_core/spec/requests/admin/themes_spec.rb new file mode 100644 index 0000000000..74ea33738f --- /dev/null +++ b/publify_core/spec/requests/admin/themes_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Admin::Themes", type: :request do + before do + create(:blog) + henri = create(:user, :as_admin) + sign_in henri + end + + describe "GET /admin/themes/switchto" do + it "is not available" do + expect { get switchto_admin_themes_path(theme: "bootstrap-2") }. + to raise_error ActiveRecord::RecordNotFound + end + end + + describe "POST /admin/themes/switchto" do + it "redirects to the themes list" do + post switchto_admin_themes_path(theme: "bootstrap-2") + expect(response).to redirect_to admin_themes_path + end + end +end diff --git a/spec/features/switch_theme_spec.rb b/spec/features/switch_theme_spec.rb new file mode 100644 index 0000000000..6c19064a7c --- /dev/null +++ b/spec/features/switch_theme_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.feature "Changing themes", type: :feature do + let(:admin) { create :user, :as_admin } + let(:blog) { Blog.first } + + before do + load Rails.root.join("db/seeds.rb") + Blog.first.update blog_name: "Awesome!", base_url: "http://www.example.com/" + end + + scenario "switching themes by clicking links in the themes admin" do + sign_in admin + visit "/admin/themes" + + expect(page).to have_text "plain - Active theme" + + click_link_or_button "Use this theme" + + expect(page).to have_text "bootstrap-2 - Active theme" + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 0ef176d422..c565f99009 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -33,6 +33,7 @@ class ActionView::TestCase::TestController # Test helpers needed for Devise config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::IntegrationHelpers, type: :feature # Test helpers to check feed contents config.include PublifyCore::TestingSupport::FeedAssertions, type: :controller