Add tests
This commit is contained in:
@@ -18,6 +18,7 @@ class Public::Collections::CardPreviewsController < ApplicationController
|
||||
@collection.cards.closed.recently_closed_first
|
||||
else
|
||||
head :bad_request
|
||||
Card.none
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= turbo_stream.remove "#{params[:target]}-load-page-#{@page.number}" %>
|
||||
|
||||
<%= turbo_stream.append params[:target] do %>
|
||||
<%= render partial: "cards/display/preview",
|
||||
<%= render partial: "cards/display/public_preview",
|
||||
collection: @page.records, as: :card, cached: true %>
|
||||
|
||||
<% unless @page.last? %>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
require "test_helper"
|
||||
|
||||
class Public::Collections::CardPreviewsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
|
||||
collections(:writebook).publish
|
||||
end
|
||||
|
||||
test "render considering cards" do
|
||||
assert cards(:text).considering?
|
||||
assert_not cards(:logo).considering?
|
||||
|
||||
get public_collection_card_previews_path(collections(:writebook).publication.key, target: "considering-cards", format: :turbo_stream)
|
||||
|
||||
assert_select ".card", text: /#{cards(:text).title}/
|
||||
assert_select ".card", text: cards(:logo).title, count: 0
|
||||
end
|
||||
|
||||
test "render doing cards" do
|
||||
assert cards(:logo).doing?
|
||||
assert_not cards(:text).doing?
|
||||
|
||||
get public_collection_card_previews_path(collections(:writebook).publication.key, target: "doing-cards", format: :turbo_stream)
|
||||
|
||||
assert_select ".card", text: /#{cards(:logo).title}/
|
||||
assert_select ".card", text: cards(:text).title, count: 0
|
||||
end
|
||||
|
||||
test "render closed cards" do
|
||||
assert cards(:shipping).closed?
|
||||
assert_not cards(:text).doing?
|
||||
|
||||
get public_collection_card_previews_path(collections(:writebook).publication.key, target: "closed-cards", format: :turbo_stream)
|
||||
|
||||
assert_select ".card", text: /#{cards(:shipping).title}/
|
||||
assert_select ".card", text: cards(:text).title, count: 0
|
||||
end
|
||||
|
||||
test "bad response for unknown target" do
|
||||
get public_collection_card_previews_path(collections(:writebook).publication.key, format: :turbo_stream)
|
||||
assert_response :bad_request
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
require "test_helper"
|
||||
|
||||
class Public::CollectionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
|
||||
collections(:writebook).publish
|
||||
end
|
||||
|
||||
test "show" do
|
||||
get published_collection_path(collections(:writebook))
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "not found if the collection is not published" do
|
||||
key = collections(:writebook).publication.key
|
||||
|
||||
collections(:writebook).unpublish
|
||||
get public_collection_path(key)
|
||||
|
||||
assert_response :not_found
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,55 @@
|
||||
require "test_helper"
|
||||
|
||||
class Collection::PublishableTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
end
|
||||
|
||||
test "published scope" do
|
||||
collections(:writebook).publish
|
||||
assert_includes Collection.published, collections(:writebook)
|
||||
assert_not_includes Collection.published, collections(:private)
|
||||
end
|
||||
|
||||
test "published?" do
|
||||
assert_not collections(:writebook).published?
|
||||
collections(:writebook).publish
|
||||
assert collections(:writebook).published?
|
||||
end
|
||||
|
||||
test "publish and unpublish" do
|
||||
assert_not collections(:writebook).published?
|
||||
|
||||
assert_difference -> { Collection::Publication.count }, +1 do
|
||||
collections(:writebook).publish
|
||||
end
|
||||
|
||||
assert collections(:writebook).published?
|
||||
|
||||
assert_difference -> { Collection::Publication.count }, -1 do
|
||||
collections(:writebook).unpublish
|
||||
end
|
||||
|
||||
assert_not collections(:writebook).reload.published?
|
||||
end
|
||||
|
||||
test "find collection by publication key" do
|
||||
collections(:writebook).publish
|
||||
assert_equal collections(:writebook), Collection.find_by_published_key(collections(:writebook).publication.key)
|
||||
|
||||
assert_raise ActiveRecord::RecordNotFound do
|
||||
Collection.find_by_published_key("invalid")
|
||||
end
|
||||
end
|
||||
|
||||
test "publish doesn't create duplicate publications" do
|
||||
collections(:writebook).publish
|
||||
original_publication = collections(:writebook).publication
|
||||
|
||||
assert_no_difference -> { Collection::Publication.count } do
|
||||
collections(:writebook).publish
|
||||
end
|
||||
|
||||
assert_equal original_publication, collections(:writebook).reload.publication
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user