Skip to content

Commit

Permalink
Basic controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KludgeKML committed Oct 17, 2024
1 parent 6f28754 commit 3715b21
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions test/functional/admin/landing_pages_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
require "test_helper"

class Admin::LandingPagesControllerTest < ActionController::TestCase
setup do
login_as :gds_admin
end

should_be_an_admin_controller

test "GET :new prepares an unsaved instance" do
get :new

assert assigns(:edition).is_a? LandingPage
assert_not assigns(:edition).persisted?
assert_response :success
assert_template "new"
end

test "POST :create saves a new instance with the supplied valid params" do
landing_page_attrs = attributes_for(:landing_page, title: "Hello there", summary: "Landing page summary", body: "blocks:")
.merge(
document_attributes: {
slug: "/landing-page/test",
},
)

post :create, params: { edition: landing_page_attrs }

assert assigns(:edition).persisted?
assert_equal "Hello there", assigns(:edition).title
assert_equal "Landing page summary", assigns(:edition).summary
assert_equal "blocks:", assigns(:edition).body
assert_equal "/landing-page/test", assigns(:edition).base_path
assert_redirected_to admin_landing_page_path(assigns(:edition))
end

test "POST :create doesn't save the new instance when the supplied params are invalid" do
attrs = attributes_for(:landing_page, title: "")

post :create, params: { edition: attrs }

assert_not assigns(:edition).persisted?
assert_response :success
assert_template "new"
end

test "GET :edit fetches the supplied instance" do
page = create(:landing_page)

get :edit, params: { id: page }

assert_equal page, assigns(:edition)
assert_response :success
assert_template "edit"
end

test "PUT :update changes the supplied instance with the supplied params" do
attrs = attributes_for(:landing_page, title: "Hello there")
page = create(:landing_page, title: "Goodbye")

post :update, params: {
id: page,
edition: attrs,
}

assert_equal page, assigns(:edition)
assert_equal "Hello there", page.reload.title
assert_redirected_to admin_landing_page_path(page)
end

test "PUT :update doesn't save the new instance when the supplied params are invalid" do
attrs = attributes_for(:landing_page, title: "")
page = create(:landing_page, title: "Goodby")

post :update, params: { id: page, edition: attrs }

assert_equal page, assigns(:edition)
assert_not_equal "", page.reload.title
assert_equal "", assigns(:edition).title
assert_response :success
assert_template "edit"
end
end

0 comments on commit 3715b21

Please sign in to comment.