Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.20.2 to 2.21.2. - [Release notes](https://github.com/rubocop/rubocop-rails/releases) - [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop-rails/compare/v2.20.2...v2.21.2) --- updated-dependencies: - dependency-name: rubocop-rails dependency-type: direct:development update-type: version-update:semver-minor ... Note version 2.21.0 relaxes the default `Include` path for `Rails/FindEach`, and so this version can find and correct offenses outside the `app/models/` folder [1]. Also note this version replaces `unless something.include?` with `if something.exclude?`; since we don't use the `exclude?` method anywhere, we're removing the `include?` method from the list of methods checked by this cop. Finally, the Rails/HttpStatus method now returns a false positive when rendering a dashboard partial and passing the `status` variable. In order to avoid this issue, we could change the name of the local variable or move the partial to a component, but for now we're simply excluding these files for this cop. [1] https://github.com/rubocop/rubocop-rails/pull/1059/commits/0066b3505 Signed-off-by: dependabot[bot] <support@github.com>
92 lines
3.1 KiB
Ruby
92 lines
3.1 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Shared::BannerComponent do
|
|
it "renders given a banner" do
|
|
banner = create(:banner,
|
|
title: "Vote now!",
|
|
description: "Banner description",
|
|
target_url: "http://www.url.com",
|
|
post_started_at: (Date.current - 4.days),
|
|
post_ended_at: (Date.current + 10.days),
|
|
background_color: "#FF0000",
|
|
font_color: "#FFFFFF")
|
|
|
|
render_inline Shared::BannerComponent.new(banner)
|
|
|
|
expect(page.find(".banner")).to have_content "Vote now!"
|
|
expect(page.find(".banner")).to have_content "Banner description"
|
|
expect(page.find(".banner")[:style]).to eq("background-color:#FF0000;")
|
|
expect(page.find("h2")[:style]).to eq("color:#FFFFFF;")
|
|
expect(page.find("h3")[:style]).to eq("color:#FFFFFF;")
|
|
expect(page).to have_link href: "http://www.url.com"
|
|
end
|
|
|
|
it "renders given a section" do
|
|
create(:banner, web_sections: [WebSection.find_by!(name: "debates")], title: "Debate banner")
|
|
create(:banner, web_sections: [WebSection.find_by!(name: "proposals")], title: "Proposal banner")
|
|
|
|
render_inline Shared::BannerComponent.new("debates")
|
|
|
|
expect(page.find(".banner")).to have_content "Debate banner"
|
|
expect(page).not_to have_content "Proposal banner"
|
|
end
|
|
|
|
context "several banners available in the same section" do
|
|
before do
|
|
create(:banner,
|
|
web_sections: [WebSection.find_by!(name: "debates")],
|
|
title: "First banner",
|
|
description: "First description",
|
|
target_url: "/first_target")
|
|
|
|
create(:banner,
|
|
web_sections: [WebSection.find_by!(name: "debates")],
|
|
title: "Second banner",
|
|
description: "Second description",
|
|
target_url: "/second_target")
|
|
end
|
|
|
|
it "only renders one banner" do
|
|
render_inline Shared::BannerComponent.new("debates")
|
|
|
|
expect(page).to have_css ".banner", count: 1
|
|
end
|
|
|
|
it "consistently renders one banner" do
|
|
render_inline Shared::BannerComponent.new("debates")
|
|
|
|
if page.has_content?("First banner")
|
|
expect(page).to have_content "First description"
|
|
expect(page).to have_css "[href='/first_target']"
|
|
expect(page).not_to have_content "Second banner"
|
|
else
|
|
expect(page).to have_content "Second description"
|
|
expect(page).to have_css "[href='/second_target']"
|
|
end
|
|
end
|
|
|
|
it "only renders active banners" do
|
|
Banner.first.update!(post_ended_at: Date.current - 1.day)
|
|
|
|
render_inline Shared::BannerComponent.new("debates")
|
|
|
|
expect(page).to have_content "Second banner"
|
|
expect(page).not_to have_content "First banner"
|
|
end
|
|
|
|
it "does not render anything with no active banners" do
|
|
Banner.all.find_each { |banner| banner.update!(post_ended_at: Date.current - 1.day) }
|
|
|
|
render_inline Shared::BannerComponent.new("debates")
|
|
|
|
expect(page).not_to be_rendered
|
|
end
|
|
end
|
|
|
|
it "does not render anything given nil" do
|
|
render_inline Shared::BannerComponent.new(nil)
|
|
|
|
expect(page).not_to be_rendered
|
|
end
|
|
end
|