Add nested imageable shared spec to check nested images behavior at imageable any recipients.
This commit is contained in:
@@ -462,9 +462,17 @@ feature 'Budget Investments' do
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "followable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }
|
||||
|
||||
it_behaves_like "imageable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }
|
||||
|
||||
it_behaves_like "followable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }
|
||||
it_behaves_like "nested imageable",
|
||||
"budget_investment",
|
||||
"new_budget_investment_path",
|
||||
{ "budget_id": "budget_id" },
|
||||
"imageable_fill_new_valid_budget_investment",
|
||||
"Create Investment",
|
||||
"Budget Investment created successfully."
|
||||
|
||||
it_behaves_like "documentable", "budget_investment", "budget_investment_path", {"budget_id": "budget_id", "id": "id"}
|
||||
|
||||
@@ -472,7 +480,7 @@ feature 'Budget Investments' do
|
||||
"budget_investment",
|
||||
"new_budget_investment_path",
|
||||
{ "budget_id": "budget_id" },
|
||||
"fill_new_valid_budget_investment",
|
||||
"documentable_fill_new_valid_budget_investment",
|
||||
"Create Investment",
|
||||
"Budget Investment created successfully."
|
||||
|
||||
|
||||
@@ -1272,9 +1272,25 @@ feature 'Proposals' do
|
||||
expect(Flag.flagged?(user, proposal)).to_not be
|
||||
end
|
||||
|
||||
it_behaves_like "followable", "proposal", "proposal_path", { "id": "id" }
|
||||
|
||||
it_behaves_like "imageable", "proposal", "proposal_path", { "id": "id" }
|
||||
|
||||
it_behaves_like "followable", "proposal", "proposal_path", { "id": "id" }
|
||||
it_behaves_like "nested imageable",
|
||||
"proposal",
|
||||
"new_proposal_path",
|
||||
{ },
|
||||
"imageable_fill_new_valid_proposal",
|
||||
"Create proposal",
|
||||
"Proposal created successfully"
|
||||
|
||||
it_behaves_like "nested imageable",
|
||||
"proposal",
|
||||
"edit_proposal_path",
|
||||
{ "id": "id" },
|
||||
nil,
|
||||
"Save changes",
|
||||
"Proposal updated successfully"
|
||||
|
||||
it_behaves_like "documentable", "proposal", "proposal_path", { "id": "id" }
|
||||
|
||||
@@ -1282,7 +1298,7 @@ feature 'Proposals' do
|
||||
"proposal",
|
||||
"new_proposal_path",
|
||||
{ },
|
||||
"fill_new_valid_proposal",
|
||||
"documentable_fill_new_valid_proposal",
|
||||
"Create proposal",
|
||||
"Proposal created successfully"
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
|
||||
expect(page).to have_selector ".file-name", text: "empty.pdf"
|
||||
end
|
||||
@@ -89,7 +89,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
|
||||
expect(find("##{documentable_factory_name}_documents_attributes_0_title").value).to eq "empty.pdf"
|
||||
end
|
||||
@@ -111,7 +111,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title"
|
||||
|
||||
expect(page).to have_selector ".loading-bar.complete"
|
||||
@@ -121,7 +121,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/logo_header.png")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/logo_header.png")
|
||||
|
||||
expect(page).to have_selector ".loading-bar.errors"
|
||||
end
|
||||
@@ -130,7 +130,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
|
||||
expect(find("input[name='#{documentable_factory_name}[documents_attributes][0][cached_attachment]']", visible: false).value).to include("empty.pdf")
|
||||
end
|
||||
@@ -139,7 +139,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/logo_header.png")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/logo_header.png")
|
||||
|
||||
expect(find("input[name='#{documentable_factory_name}[documents_attributes][0][cached_attachment]']", visible: false).value).to eq ""
|
||||
end
|
||||
@@ -161,7 +161,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
within "#document_0" do
|
||||
click_link "Remove document"
|
||||
end
|
||||
@@ -173,7 +173,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
within "#document_0" do
|
||||
click_link "Remove document"
|
||||
end
|
||||
@@ -195,7 +195,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
visit send(path, arguments)
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
|
||||
click_on submit_button
|
||||
expect(page).to have_content documentable_success_notice
|
||||
@@ -206,10 +206,10 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
visit send(path, arguments)
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
|
||||
click_on submit_button
|
||||
redirected_to_resource_show_or_navigate_to
|
||||
documentable_redirected_to_resource_show_or_navigate_to
|
||||
|
||||
expect(page).to have_content "Documents (1)"
|
||||
end
|
||||
@@ -220,11 +220,11 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
documentable.class.max_documents_allowed.times.each do |index|
|
||||
attach_new_file(documentable_factory_name, index, "spec/fixtures/files/empty.pdf")
|
||||
documentable_attach_new_file(documentable_factory_name, index , "spec/fixtures/files/empty.pdf")
|
||||
end
|
||||
|
||||
click_on submit_button
|
||||
redirected_to_resource_show_or_navigate_to
|
||||
documentable_redirected_to_resource_show_or_navigate_to
|
||||
|
||||
expect(page).to have_content "Documents (#{documentable.class.max_documents_allowed})"
|
||||
end
|
||||
@@ -233,31 +233,30 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
|
||||
|
||||
end
|
||||
|
||||
def redirected_to_resource_show_or_navigate_to
|
||||
def documentable_redirected_to_resource_show_or_navigate_to
|
||||
find("a", text: "Not now, go to my proposal")
|
||||
click_on "Not now, go to my proposal"
|
||||
rescue
|
||||
return
|
||||
end
|
||||
|
||||
def attach_new_file(documentable_factory_name, index, path)
|
||||
def documentable_attach_new_file(documentable_factory_name, index, path)
|
||||
click_link "Add new document"
|
||||
sleep 1
|
||||
attach_file("#{documentable_factory_name}[documents_attributes][#{index}][attachment]", path, make_visible: true)
|
||||
sleep 1
|
||||
end
|
||||
|
||||
def fill_new_valid_proposal
|
||||
def documentable_fill_new_valid_proposal
|
||||
fill_in :proposal_title, with: "Proposal title #{rand(9999)}"
|
||||
fill_in :proposal_summary, with: "Proposal summary"
|
||||
fill_in :proposal_question, with: "Proposal question?"
|
||||
check :proposal_terms_of_service
|
||||
end
|
||||
|
||||
def fill_new_valid_budget_investment
|
||||
def documentable_fill_new_valid_budget_investment
|
||||
page.select documentable.heading.name_scoped_by_group, from: :budget_investment_heading_id
|
||||
fill_in :budget_investment_title, with: "Budget investment title"
|
||||
fill_in_ckeditor "budget_investment_description", with: "Budget investment description"
|
||||
check :budget_investment_terms_of_service
|
||||
end
|
||||
|
||||
|
||||
199
spec/shared/features/nested_imageable.rb
Normal file
199
spec/shared/features/nested_imageable.rb
Normal file
@@ -0,0 +1,199 @@
|
||||
shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice|
|
||||
include ActionView::Helpers
|
||||
include ImagesHelper
|
||||
include ImageablesHelper
|
||||
|
||||
let!(:administrator) { create(:user) }
|
||||
let!(:user) { create(:user, :level_two) }
|
||||
let!(:arguments) { {} }
|
||||
let!(:imageable) { create(imageable_factory_name, author: user) }
|
||||
|
||||
before do
|
||||
create(:administrator, user: administrator)
|
||||
|
||||
if imageable_path_arguments
|
||||
imageable_path_arguments.each do |argument_name, path_to_value|
|
||||
arguments.merge!("#{argument_name}": imageable.send(path_to_value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "at #{path}" do
|
||||
|
||||
scenario "Should show new image link when imageable has not an associated image defined" do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).to have_selector "#new_image_link", visible: true
|
||||
end
|
||||
|
||||
scenario "Should update nested image file name after choosing a file", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||
|
||||
expect(page).to have_selector ".file-name", text: "empty.pdf"
|
||||
end
|
||||
|
||||
scenario "Should update nested image file title with file name after choosing a file when no title defined", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/clippy.jpg")
|
||||
|
||||
expect(find("##{imageable_factory_name}_image_attributes_title").value).to eq "clippy.jpg"
|
||||
end
|
||||
|
||||
scenario "Should not update nested image file title with file name after choosing a file when title already defined", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
click_link "Add image"
|
||||
sleep 1
|
||||
fill_in "#{imageable_factory_name}[image_attributes]title", with: "Title"
|
||||
attach_file("#{imageable_factory_name}[image_attributes]attachment", "spec/fixtures/files/empty.pdf", make_visible: true)
|
||||
sleep 1
|
||||
|
||||
expect(find("##{imageable_factory_name}_image_attributes_title").value).to eq "Title"
|
||||
end
|
||||
|
||||
scenario "Should update loading bar style after valid file upload", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/clippy.jpg")
|
||||
|
||||
expect(page).to have_selector ".loading-bar.complete"
|
||||
end
|
||||
|
||||
scenario "Should update loading bar style after unvalid file upload", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/logo_header.png")
|
||||
|
||||
expect(page).to have_selector ".loading-bar.errors"
|
||||
end
|
||||
|
||||
scenario "Should update image cached_attachment field after valid file upload", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/clippy.jpg")
|
||||
|
||||
expect(find("input[name='#{imageable_factory_name}[image_attributes]cached_attachment']", visible: false).value).to include("clippy.jpg")
|
||||
end
|
||||
|
||||
scenario "Should not update image cached_attachment field after unvalid file upload", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/logo_header.png")
|
||||
|
||||
expect(find("input[name='#{imageable_factory_name}[image_attributes]cached_attachment']", visible: false).value).to eq ""
|
||||
end
|
||||
|
||||
scenario "Should show image errors after unvalid file upload", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
click_link "Add image"
|
||||
sleep 1
|
||||
click_on submit_button
|
||||
|
||||
within "#nested_image" do
|
||||
expect(page).to have_content("can't be blank", count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Should delete image after valid file upload and click on remove button", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/clippy.jpg")
|
||||
within "#nested_image" do
|
||||
click_link "Remove image"
|
||||
end
|
||||
|
||||
expect(page).not_to have_selector("#nested_image")
|
||||
end
|
||||
|
||||
scenario "Should delete image after valid file upload and click on remove button", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/clippy.jpg")
|
||||
within "#nested_image" do
|
||||
click_link "Remove image"
|
||||
end
|
||||
|
||||
expect(page).to have_content "Image was deleted successfully."
|
||||
end
|
||||
|
||||
scenario "Should show successful notice when resource filled correctly without any nested images", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
click_on submit_button
|
||||
expect(page).to have_content imageable_success_notice
|
||||
end
|
||||
|
||||
scenario "Should show successful notice when resource filled correctly and after valid file uploads", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/clippy.jpg")
|
||||
|
||||
click_on submit_button
|
||||
expect(page).to have_content imageable_success_notice
|
||||
end
|
||||
|
||||
scenario "Should show new image after successful creation with one uploaded file", :js do
|
||||
login_as user
|
||||
visit send(path, arguments)
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
imageable_attach_new_file(imageable_factory_name, 0, "spec/fixtures/files/clippy.jpg")
|
||||
|
||||
click_on submit_button
|
||||
imageable_redirected_to_resource_show_or_navigate_to
|
||||
|
||||
expect(page).to have_selector "figure .image"
|
||||
expect(page).to have_selector "figure figcaption"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def imageable_redirected_to_resource_show_or_navigate_to
|
||||
find("a", text: "Not now, go to my proposal")
|
||||
click_on "Not now, go to my proposal"
|
||||
rescue
|
||||
return
|
||||
end
|
||||
|
||||
def imageable_attach_new_file(imageable_factory_name, index, path)
|
||||
click_link "Add image"
|
||||
sleep 1
|
||||
attach_file("#{imageable_factory_name}[image_attributes]attachment", path, make_visible: true)
|
||||
sleep 1
|
||||
end
|
||||
|
||||
def imageable_fill_new_valid_proposal
|
||||
fill_in :proposal_title, with: "Proposal title"
|
||||
fill_in :proposal_summary, with: "Proposal summary"
|
||||
fill_in :proposal_question, with: "Proposal question?"
|
||||
check :proposal_terms_of_service
|
||||
end
|
||||
|
||||
def imageable_fill_new_valid_budget_investment
|
||||
page.select imageable.heading.name_scoped_by_group, from: :budget_investment_heading_id
|
||||
fill_in :budget_investment_title, with: "Budget investment title"
|
||||
fill_in_ckeditor "budget_investment_description", with: "Budget investment description"
|
||||
check :budget_investment_terms_of_service
|
||||
end
|
||||
Reference in New Issue
Block a user