diff --git a/app/controllers/merged/cards_controller.rb b/app/controllers/merged/cards_controller.rb index b085aec..17641ac 100644 --- a/app/controllers/merged/cards_controller.rb +++ b/app/controllers/merged/cards_controller.rb @@ -8,8 +8,9 @@ module Merged def set_image @card.image_id = params[:image_id].to_i - @card.save - redirect_to section_cards_url(@card.section.id) , notice: "Image selected: #{@card.image.name}" + @card.edit_save(current_member.email) + message = @card.image ? "#{@card.image.name} selected" : "Image removed" + redirect_to section_cards_url(@card.section.id) , notice: message end def move diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index 1c01b04..4d8422f 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -34,7 +34,8 @@ module Merged def set_image @section.image_id = params[:image_id].to_i @section.edit_save(current_member.email) - redirect_to section_url(@section.id) , notice: "Image selected: #{@section.image.name}" + message = @section.image ? "#{@section.image.name} selected" : "Image removed" + redirect_to section_url(@section.id) , notice: message end def set_template diff --git a/app/views/merged/cards/index.haml b/app/views/merged/cards/index.haml index fdd8205..9693898 100644 --- a/app/views/merged/cards/index.haml +++ b/app/views/merged/cards/index.haml @@ -21,7 +21,7 @@ = form_tag( merged.card_path(card.id) , {method: :delete } ) do =submit_button( "Delete" , true) .p-4 - %h3.mt-4.text-lg.font-bold Image + %h3.mt-4.text-lg.font-bold.image_button Image = yellow_button("Change Image" , merged.images_path(card_id: card.id) ) = red_button("Remove image", merged.card_set_image_path( card.id , image: "") ) .basis-full.mt-3 @@ -42,7 +42,7 @@ = card.image.aspect_ratio = image_for( card ) -else - %h3.mt-4.text-lg.font-bold No Image + %h3.mt-4.text-lg.font-bold No image .basis-72.grow %h3.mt-4.text-lg.font-bold Fields = form_tag( merged.card_path(card.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do diff --git a/app/views/merged/sections/show.haml b/app/views/merged/sections/show.haml index 5717f03..76ef71a 100644 --- a/app/views/merged/sections/show.haml +++ b/app/views/merged/sections/show.haml @@ -19,14 +19,21 @@ Updated by: = @section.updated_by - .basis-96 - %h3.mt-4.text-lg.font-bold Image - -if( @section.image.blank? ) - %p No image - -else - = image_for( @section , "my-3") - = yellow_button("Change Image", merged.images_path(section_id: @section.id)) - = red_button( "Remove image", merged.section_set_image_path( @section.id , image: "")) + .basis-96.image + = link_to(merged.images_path(section_id: @section.id)) do + -if @section.image + %h3.mt-4.text-lg.font-bold Image #{@section.image.name} + .flex.align-center.justify-between.mb-4 + .text-lg.font-bold.mt-2.mx-2 + = @section.image.size.to_s + "k" + %strong.inline-block.rounded.bg-yellow-200.px-3.py-1.text-md.font-medium + = @section.image.aspect_ratio + = image_for( @section ) + -else + %h3.mt-4.text-lg.font-bold No Image + .flex + .mt-3= yellow_button("Change Image", merged.images_path(section_id: @section.id)) + .mt-3= red_button( "Remove image", merged.section_set_image_path( @section.id , image: "")) if( @section.image ) .basis-80.grow.content_update = section_form( class: "mx-auto mt-8 mb-0 max-w space-y-4") do diff --git a/test/integration/cards_test.rb b/test/integration/cards_test.rb index f56f913..b775411 100644 --- a/test/integration/cards_test.rb +++ b/test/integration/cards_test.rb @@ -25,4 +25,20 @@ class CardsTest < ActionDispatch::IntegrationTest find_button("Update").click end end + + class CardsWriteTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers # Rails >= 5 + include Merged::Cleanup + + def test_remove_image + visit "merged/sections/11/cards" + find_button("Remove image", match: :first).click + assert_equal 200 , page.status_code + end + + def test_remove_image_force + visit "merged/cards/6/set_image?image=''" + assert_text page , "No image" + end + end end diff --git a/test/integration/sections_test.rb b/test/integration/sections_test.rb index 2f960c8..21ba686 100644 --- a/test/integration/sections_test.rb +++ b/test/integration/sections_test.rb @@ -33,4 +33,22 @@ class SectionsTest < ActionDispatch::IntegrationTest find_button("Update").click end end + class SectionsWriteTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers # Rails >= 5 + include Merged::Cleanup + + def test_remove_image + visit "merged/sections/31" + within(".image") do + click_button("Remove image") + end + assert_equal 200 , page.status_code + end + + def test_remove_image_force + visit "merged/sections/31/set_image?image=''" + assert_text page , "No Image" + end + + end end