diff --git a/app/controllers/merged/pages_controller.rb b/app/controllers/merged/pages_controller.rb index 9cc5cef..1272a96 100644 --- a/app/controllers/merged/pages_controller.rb +++ b/app/controllers/merged/pages_controller.rb @@ -14,20 +14,19 @@ module Merged def update @page.add_redirect @page.name = params[:name] - @page.save + @page.save(current_member.email) redirect_to page_url(@page) , notice: "Page renamed" end def create name = params[:name] - message = Page.check_name(name) message = "Must enter name" if name.blank? - if( message.nil?) + if( ! message.nil?) @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." else - @pages = Page.all.values + @pages = Page.all flash.now.alert = message render :index end diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index c983941..3872af3 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -19,7 +19,7 @@ module Merged page = Page.find(params[:page_id]) template = params[:template] new_section = page.new_section(template) - new_section.save + new_section.save(current_member.email) if(template.blank?) # new redirect_to section_select_template_url(new_section.id), notice: "New section created" else # copy diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index a5c2404..94405d3 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -80,15 +80,9 @@ module Merged end def self.new_page(name ) - raise "only alphanumeric, not #{name}" unless check_name(name).nil? data = { name: name.dup , updated_at: Time.now } Page.new(data) 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 diff --git a/app/views/merged/pages/index.haml b/app/views/merged/pages/index.haml index 85ce26e..f30d317 100644 --- a/app/views/merged/pages/index.haml +++ b/app/views/merged/pages/index.haml @@ -55,7 +55,7 @@ %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) -.grid.grid-cols-3.gap-2.m-8 +.grid.grid-cols-3.gap-2.m-8.new_page .relative.block.border.border-gray-100 = form_tag( merged.pages_path , {method: :post } ) do %label.block diff --git a/app/views/merged/pages/show.haml b/app/views/merged/pages/show.haml index 08c09c5..6eff749 100644 --- a/app/views/merged/pages/show.haml +++ b/app/views/merged/pages/show.haml @@ -28,7 +28,7 @@ Page redirects from = @page.redirects - .basis-80.grow + .basis-80.grow.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 - @page.option_definitions.each do |option| diff --git a/test/integration/page_test.rb b/test/integration/page_test.rb deleted file mode 100644 index 1594df9..0000000 --- a/test/integration/page_test.rb +++ /dev/null @@ -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 diff --git a/test/integration/pages_test.rb b/test/integration/pages_test.rb new file mode 100644 index 0000000..116e340 --- /dev/null +++ b/test/integration/pages_test.rb @@ -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