more fixes for save

This commit is contained in:
Torsten 2022-12-23 17:37:49 +02:00
parent aba29b2809
commit 730b49a8bb
7 changed files with 55 additions and 37 deletions

View File

@ -14,20 +14,19 @@ module Merged
def update def update
@page.add_redirect @page.add_redirect
@page.name = params[:name] @page.name = params[:name]
@page.save @page.save(current_member.email)
redirect_to page_url(@page) , notice: "Page renamed" redirect_to page_url(@page) , notice: "Page renamed"
end end
def create def create
name = params[:name] name = params[:name]
message = Page.check_name(name)
message = "Must enter name" if name.blank? message = "Must enter name" if name.blank?
if( message.nil?) if( ! message.nil?)
@page = Page.new_page(name) @page = Page.new_page(name)
@page.save @page.save(current_member.email)
redirect_to new_page_section_url(@page.id) , notice: "Page was successfully created." redirect_to new_page_section_url(@page.id) , notice: "Page was successfully created."
else else
@pages = Page.all.values @pages = Page.all
flash.now.alert = message flash.now.alert = message
render :index render :index
end end

View File

@ -19,7 +19,7 @@ module Merged
page = Page.find(params[:page_id]) page = Page.find(params[:page_id])
template = params[:template] template = params[:template]
new_section = page.new_section(template) new_section = page.new_section(template)
new_section.save new_section.save(current_member.email)
if(template.blank?) # new if(template.blank?) # new
redirect_to section_select_template_url(new_section.id), notice: "New section created" redirect_to section_select_template_url(new_section.id), notice: "New section created"
else # copy else # copy

View File

@ -80,15 +80,9 @@ module Merged
end end
def self.new_page(name ) def self.new_page(name )
raise "only alphanumeric, not #{name}" unless check_name(name).nil?
data = { name: name.dup , updated_at: Time.now } data = { name: name.dup , updated_at: Time.now }
Page.new(data) Page.new(data)
end end
def self.check_name(name)
return "only alphanumeric, not #{name}" if name.match(/\A[a-zA-Z0-9]*\z/).nil?
nil
end
end end
end end

View File

@ -55,7 +55,7 @@
%strong.rounded.bg-amber-100.px-3.text-xs.font-medium.text-amber-700{:class => "py-1.5"} %strong.rounded.bg-amber-100.px-3.text-xs.font-medium.text-amber-700{:class => "py-1.5"}
= link_to 'Edit', merged.page_path(page.id) = link_to 'Edit', merged.page_path(page.id)
.grid.grid-cols-3.gap-2.m-8 .grid.grid-cols-3.gap-2.m-8.new_page
.relative.block.border.border-gray-100 .relative.block.border.border-gray-100
= form_tag( merged.pages_path , {method: :post } ) do = form_tag( merged.pages_path , {method: :post } ) do
%label.block %label.block

View File

@ -28,7 +28,7 @@
Page redirects from Page redirects from
= @page.redirects = @page.redirects
.basis-80.grow .basis-80.grow.options
%h3.mt-4.text-lg.font-bold Options %h3.mt-4.text-lg.font-bold Options
= form_tag( merged.page_path(@page.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do = form_tag( merged.page_path(@page.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do
- @page.option_definitions.each do |option| - @page.option_definitions.each do |option|

View File

@ -1,23 +0,0 @@
require "test_helper"
class PageTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers # Rails >= 5
def test_returns_success
visit "/merged/pages"
assert_title page, "Dummy"
assert_text page, "Pages"
end
def test_has_an_index_page
visit "merged/pages"
click_on ("index")
end
def test_edit_page_works
visit "/merged/pages"
within("#index") do
click_on ("Edit")
end
end
end

View File

@ -0,0 +1,48 @@
require "test_helper"
class PageTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers # Rails >= 5
def test_returns_success
visit "/merged/pages"
assert_title page, "Dummy"
assert_text page, "Pages"
end
def test_has_an_index_page
visit "merged/pages"
click_on ("index")
end
def test_edit_page_works
visit "/merged/pages"
within("#index") do
click_on ("Edit")
end
end
end
class PagesWrite < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers # Rails >= 5
include Merged::Cleanup
def test_edit_page_works
visit "/merged/pages/2"
within(".options") do
click_on ("Update")
end
end
def test_new_works_without
visit "/merged/pages"
within(".new_page") do
click_on ("New Page")
end
end
def test_new_works_with_name
visit "/merged/pages"
within(".new_page") do
fill_in 'Name', with: 'New Page'
click_on ("New Page")
end
end
end