We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
42 lines
1.5 KiB
Ruby
42 lines
1.5 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Admin download user emails" do
|
|
let(:admin_user) { create(:user, newsletter: false, email: "admin@consul.dev") }
|
|
|
|
before do
|
|
create(:administrator, user: admin_user)
|
|
login_as(admin_user)
|
|
end
|
|
|
|
context "Download only emails from segment users with newsletter flag & present email " do
|
|
before do
|
|
create(:user, email: "user@consul.dev")
|
|
|
|
create(:administrator, user: create(:user, newsletter: true, email: "admin_news1@consul.dev"))
|
|
create(:administrator, user: create(:user, newsletter: true, email: "admin_news2@consul.dev"))
|
|
|
|
create(:administrator, user: create(:user, newsletter: false, email: "no_news@consul.dev"))
|
|
|
|
admin_without_email = create(:user, newsletter: true, email: "no_email@consul.dev")
|
|
create(:administrator, user: admin_without_email)
|
|
admin_without_email.update_attribute(:email, nil)
|
|
end
|
|
|
|
scenario "returns the selected users segment csv file" do
|
|
visit admin_emails_download_index_path
|
|
|
|
within("#admin_download_emails") do
|
|
select "Administrators", from: "users_segment"
|
|
click_button "Download emails list"
|
|
end
|
|
|
|
header = page.response_headers["Content-Disposition"]
|
|
expect(header).to match(/^attachment/)
|
|
expect(header).to match(/filename="Administrators.csv"$/)
|
|
|
|
file_contents = page.body.split(",")
|
|
expect(file_contents).to match_array ["admin_news1@consul.dev", "admin_news2@consul.dev"]
|
|
end
|
|
end
|
|
end
|