Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ unthrottled_ips=
# Analytics
MATOMO_SITE_ID=

# Feature flags
STATE_ACTIONS_ENABLED=true

#
# End of application environment variables
#
2 changes: 2 additions & 0 deletions app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def email
# This endpoint is hit by the js for state legislator lookup-by-address actions.
# It renders json containing html markup for presentation on the view
def state_reps
raise ActionController::RoutingError.new("Not Found") unless Rails.application.config.state_actions_enabled

@email_campaign = EmailCampaign.find(params[:email_campaign_id])
@actionPage = @email_campaign.action_page
# TODO: strong params this
Expand Down
43 changes: 11 additions & 32 deletions app/views/admin/action_pages/_email_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<%= f.fields_for(:email_campaign) do |sf| %>
<% if Rails.application.config.state_actions_enabled %>
<%= render partial: "state_level_fields", locals: { sf: sf } %>
<% else %>
<div class="form-item">
<%= sf.label :email_addresses do %>
Target email(s)
<span class="hint">(Separate multiple addresses with commas, e.g. "dax@eff.org,kira@eff.org")</span>
<% end %>
<%= sf.text_field :email_addresses %>
</div>
<% end %>

<div class="form-item">
<%= sf.label :subject %>
Expand All @@ -9,36 +20,4 @@
<%= sf.label :message %>
<%= sf.text_area :message %>
</div>

<fieldset class="form-item">
<legend>Select State-Level Legislators</legend>

<%= sf.label :state, class: "fancy" do %>
<%= sf.select :state, options_for_select(EmailCampaign::STATES, @actionPage.email_campaign.state), include_blank: "- none -" %><span class="ui"></span>
<% end %>

<div id="state-level-target-selection">
<p>For now, please choose only one.</p>
<%= sf.label :target_state_lower_chamber do %>
<%= sf.check_box :target_state_lower_chamber, class: "fancy" %><span class="ui"></span>
Lower Chamber
<% end %>

<%= sf.label :target_state_upper_chamber do %>
<%= sf.check_box :target_state_upper_chamber, class: "fancy" %><span class="ui"></span>
Upper Chamber
<% end %>

<%= sf.label :target_governor do %>
<%= sf.check_box :target_governor, class: "fancy" %><span class="ui"></span>
Governor
<% end %>
</div>

<br></br>

<%= sf.label :email_addresses, "Or enter custom email addresses below:" %>
<%= sf.text_field :email_addresses %>
</fieldset>

<% end %>
30 changes: 30 additions & 0 deletions app/views/admin/action_pages/_state_level_fields.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<fieldset class="form-item">
<legend>Select State-Level Legislators</legend>

<%= sf.label :state, class: "fancy" do %>
<%= sf.select :state, options_for_select(EmailCampaign::STATES, @actionPage.email_campaign.state), include_blank: "- none -" %><span class="ui"></span>
<% end %>

<div id="state-level-target-selection">
<p>For now, please choose only one.</p>
<%= sf.label :target_state_lower_chamber do %>
<%= sf.check_box :target_state_lower_chamber, class: "fancy" %><span class="ui"></span>
Lower Chamber
<% end %>

<%= sf.label :target_state_upper_chamber do %>
<%= sf.check_box :target_state_upper_chamber, class: "fancy" %><span class="ui"></span>
Upper Chamber
<% end %>

<%= sf.label :target_governor do %>
<%= sf.check_box :target_governor, class: "fancy" %><span class="ui"></span>
Governor
<% end %>
</div>

<br></br>

<%= sf.label :email_addresses, "Or enter custom email addresses below:" %>
<%= sf.text_field :email_addresses %>
</fieldset>
2 changes: 1 addition & 1 deletion app/views/tools/_container.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= render "tools/petition" if @actionPage.enable_petition? && @actionPage.petition %>
<%= render "tools/call" if @actionPage.enable_call? && @actionPage.call_campaign %>
<% if @actionPage.enable_email? && @actionPage.email_campaign %>
<% if @actionPage.email_campaign.state? %>
<% if Rails.application.config.state_actions_enabled && @actionPage.email_campaign.state? %>
<%= render "tools/state_leg_email" %>
<% else %>
<%= render "tools/email" %>
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ class Application < Rails::Application
config.congress_forms_url = Rails.application.secrets.congress_forms_url
config.google_civic_api_url = Rails.application.secrets.google_civic_api_url
config.time_zone = Rails.application.secrets.time_zone || "Eastern Time (US & Canada)"

config.state_actions_enabled = Rails.application.secrets.state_actions_enabled
end
end
24 changes: 15 additions & 9 deletions spec/requests/tools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@
let!(:headers) { { "CONTENT_TYPE" => "application/javascript" } }

describe "POST tools/state_reps" do
it "returns json containing rep data for a given address" do
civic_api = class_double("CivicApi")
.as_stubbed_const(transfer_nested_constants: true)
allow(civic_api).to receive(:state_rep_search)
.with(address, campaign.leg_level)
.and_return(officials)
context "when state actions enabled" do
before do
allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }
end

post "/tools/state_reps", params: params, xhr: true
it "returns json containing rep data for a given address" do
civic_api = class_double("CivicApi")
.as_stubbed_const(transfer_nested_constants: true)
allow(civic_api).to receive(:state_rep_search)
.with(address, campaign.leg_level)
.and_return(officials)

expect(response).to have_http_status(200)
expect(response.body).to include(officials.first["name"])
post "/tools/state_reps", params: params, xhr: true

expect(response).to have_http_status(200)
expect(response.body).to include(officials.first["name"])
end
end
end
end
3 changes: 3 additions & 0 deletions spec/support/javascript_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def fill_in_editor(locator, with:)
end
end

# TODO: fix? this did not work for action filters, but those also live in
# a sidebar and this isn't breaking elsewhere
# but this does not fill in every select2 correctly
def fill_in_select2(locator, with:)
find(locator).sibling(".select2-container").click
find("li.select2-results__option[role=option]", text: with).click
Expand Down
2 changes: 2 additions & 0 deletions spec/system/action_pages/state_leg_email_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
before do
stub_request(:get, "https://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody")
.to_return(status: 200, body: data.to_json, headers: {})

allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }
end

it "allows vistors to see look up their representatives" do
Expand Down
53 changes: 36 additions & 17 deletions spec/system/admin/action_creation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
select_action_type("email")
fill_in "Subject", with: "Subject"
fill_in "Message", with: "An email"
fill_in "Or enter custom email addresses below:", with: "test@gmail.com"
fill_in "Target email(s)", with: "test@gmail.com"
next_section

skip_banner_selection
Expand All @@ -61,27 +61,46 @@
expect(page).to have_content("Very Important Action", wait: 10)
end

it "can create state-level email actions" do
visit new_admin_action_page_path
fill_in_basic_info(title: "State-Level Leg Action",
summary: "A summary",
description: "A description")
click_on "Next"
context "when state-level email actions enabled" do
it "can create state-level email actions" do
allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }

select_action_type("email")
fill_in "Subject", with: "Subject"
fill_in "Message", with: "An email"
visit new_admin_action_page_path
fill_in_basic_info(title: "State-Level Leg Action",
summary: "A summary",
description: "A description")
click_on "Next"

select("CA", from: "action_page_email_campaign_attributes_state")
find("#action_page_email_campaign_attributes_target_state_upper_chamber").ancestor("label").click
select_action_type("email")
fill_in "Subject", with: "Subject"
fill_in "Message", with: "An email"

click_on "Next"
expect(page).to have_content("Select State-Level Legislators")
select("CA", from: "action_page_email_campaign_attributes_state")
find("#action_page_email_campaign_attributes_target_state_upper_chamber").ancestor("label").click

skip_banner_selection
fill_in_social_media
click_on "Next"

click_button "Save"
expect(page).to have_content("State-Level Leg Action", wait: 10)
skip_banner_selection
fill_in_social_media

click_button "Save"
expect(page).to have_content("State-Level Leg Action", wait: 10)
end
end

context "when state-levle email actions are not enabled" do
it "does not show the option to create a state-level campaign" do
visit new_admin_action_page_path
fill_in_basic_info(title: "State-Level Leg Action",
summary: "A summary",
description: "A description")
click_on "Next"

select_action_type("email")

expect(page).to_not have_content("Select State-Level Legislators")
end
end

it "can create congress actions" do
Expand Down
3 changes: 2 additions & 1 deletion spec/system/admin/action_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
email_action = FactoryBot.create(:action_page, enable_email: true)

visit admin_action_pages_path
fill_in_select2("#action_filters_type", with: "email")
find("#action_filters_type").sibling(".select2-container").click
find("ul#select2-action_filters_type-results li", text: "email").click
click_on "Search"

expect(page).to have_content(email_action.title)
Expand Down