Merge pull request #3974 from consul/action_view_in_specs

Don't include unneeded helpers in tests
This commit is contained in:
Javier Martín
2020-04-16 12:35:50 +02:00
committed by GitHub
19 changed files with 7 additions and 107 deletions

View File

@@ -8,7 +8,7 @@ module DocumentablesHelper
end
def max_file_size(documentable_class)
bytes_to_mega(documentable_class.max_file_size)
documentable_class.max_file_size / Numeric::MEGABYTE
end
def accepted_content_types(documentable_class)

View File

@@ -7,10 +7,6 @@ module DocumentsHelper
document.errors[:attachment].join(", ") if document.errors.key?(:attachment)
end
def bytes_to_mega(bytes)
bytes / Numeric::MEGABYTE
end
def render_destroy_document_link(builder, document)
if !document.persisted? && document.cached_attachment.present?
link_to t("documents.form.delete_button"),

View File

@@ -4,11 +4,7 @@ module ImageablesHelper
end
def imageable_max_file_size
bytes_to_megabytes(Setting["uploads.images.max_size"].to_i.megabytes)
end
def bytes_to_megabytes(bytes)
bytes / Numeric::MEGABYTE
Setting["uploads.images.max_size"].to_i
end
def imageable_accepted_content_types

View File

@@ -1,5 +1,4 @@
require "rails_helper"
include ActionView::Helpers::DateHelper
describe "Commenting Budget::Investments" do
let(:user) { create :user }

View File

@@ -1,5 +1,4 @@
require "rails_helper"
include ActionView::Helpers::DateHelper
describe "Commenting debates" do
let(:user) { create :user }

View File

@@ -1,5 +1,4 @@
require "rails_helper"
include ActionView::Helpers::DateHelper
describe "Commenting legislation questions" do
let(:user) { create :user }

View File

@@ -1,5 +1,4 @@
require "rails_helper"
include ActionView::Helpers::DateHelper
describe "Commenting legislation questions" do
let(:user) { create :user, :level_two }

View File

@@ -1,5 +1,4 @@
require "rails_helper"
include ActionView::Helpers::DateHelper
describe "Commenting polls" do
let(:user) { create :user }

View File

@@ -1,5 +1,4 @@
require "rails_helper"
include ActionView::Helpers::DateHelper
describe "Commenting proposals" do
let(:user) { create :user }

View File

@@ -1,5 +1,4 @@
require "rails_helper"
include ActionView::Helpers::DateHelper
describe "Commenting topics from proposals" do
let(:user) { create :user }

View File

@@ -1,6 +1,4 @@
shared_examples "documentable" do |documentable_factory_name, documentable_path, documentable_path_arguments|
include ActionView::Helpers
let(:administrator) { create(:user) }
let(:user) { create(:user) }
let(:arguments) { {} }
@@ -134,7 +132,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
click_on "Delete document"
end
within "##{dom_id(documentable)}" do
within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do
expect(page).to have_selector "h1", text: documentable.title
end
end

View File

@@ -1,10 +1,12 @@
shared_examples "followable" do |followable_class_name, followable_path, followable_path_arguments|
include ActionView::Helpers
let!(:arguments) { {} }
let!(:followable) { create(followable_class_name) }
let!(:followable_dom_name) { followable_class_name.tr("_", "-") }
def dom_id(record)
ActionView::RecordIdentifier.dom_id(record)
end
before do
followable_path_arguments.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": followable.send(path_to_value))

View File

@@ -1,8 +1,4 @@
shared_examples "imageable" do |imageable_factory_name, imageable_path, imageable_path_arguments|
include ActionView::Helpers
include ImagesHelper
include ImageablesHelper
let!(:administrator) { create(:user) }
let!(:user) { create(:user) }
let!(:imageable_arguments) { {} }

View File

@@ -1,69 +0,0 @@
shared_examples "imageable destroy" do |imageable_factory_name, imageable_path, imageable_path_arguments|
include ActionView::Helpers
include ImagesHelper
include ImageablesHelper
let!(:administrator) { create(:user) }
let!(:user) { create(:user) }
let!(:imageable_arguments) { {} }
let!(:imageables_arguments) { {} }
let!(:imageable) { create(imageable_factory_name, author: user) }
let!(:imageable_dom_name) { imageable_factory_name.parameterize }
before do
create(:administrator, user: administrator)
imageable_path_arguments.each do |argument_name, path_to_value|
imageable_arguments.merge!("#{argument_name}": imageable.send(path_to_value))
end
end
context "Destroy" do
before do
create(:image, imageable: imageable, user: imageable.author)
end
scenario "Administrators cannot destroy imageables they have not authored" do
login_as(administrator)
visit send(imageable_path, imageable_arguments)
expect(page).not_to have_link "Remove image"
end
scenario "Users cannot destroy imageables they have not authored" do
login_as(create(:user))
visit send(imageable_path, imageable_arguments)
expect(page).not_to have_link "Remove image"
end
scenario "Should show success notice after successful deletion" do
login_as imageable.author
visit send(imageable_path, imageable_arguments)
click_on "Remove image"
expect(page).to have_content "Image was deleted successfully."
end
scenario "Should not show image after successful deletion" do
login_as imageable.author
visit send(imageable_path, imageable_arguments)
click_on "Remove image"
expect(page).not_to have_selector "figure img"
end
scenario "Should redirect to imageable path after successful deletion" do
login_as imageable.author
visit send(imageable_path, imageable_arguments)
click_on "Remove image"
within "##{dom_id(imageable)}" do
expect(page).to have_selector "h1", text: imageable.title
end
end
end
end

View File

@@ -1,6 +1,4 @@
shared_examples "mappable" do |mappable_factory_name, mappable_association_name, mappable_new_path, mappable_edit_path, mappable_show_path, mappable_path_arguments, management: false|
include ActionView::Helpers
let!(:user) { create(:user, :level_two) }
let!(:arguments) { {} }
let!(:mappable) { create(mappable_factory_name.to_s.to_sym) }

View File

@@ -1,8 +1,4 @@
shared_examples "nested documentable" do |login_as_name, documentable_factory_name, path, documentable_path_arguments, fill_resource_method_name, submit_button, documentable_success_notice|
include ActionView::Helpers
include DocumentsHelper
include DocumentablesHelper
let!(:administrator) { create(:user) }
let!(:user) { create(:user, :level_two) }
let!(:arguments) { {} }

View File

@@ -1,8 +1,4 @@
shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice, has_many_images = false|
include ActionView::Helpers
include ImagesHelper
include ImageablesHelper
let!(:user) { create(:user, :level_two) }
let!(:administrator) { create(:administrator, user: user) }
let!(:arguments) { {} }

View File

@@ -1,5 +1,4 @@
shared_examples "document validations" do |documentable_factory|
include DocumentsHelper
include DocumentablesHelper
let!(:document) { build(:document, documentable_factory.to_sym) }

View File

@@ -1,5 +1,4 @@
shared_examples "image validations" do |imageable_factory|
include ImagesHelper
include ImageablesHelper
let!(:image) { build(:image, imageable_factory.to_sym) }