Change Newsletter's segment_recipient to string

Why:

Newsletter attribute `segment_recipient` is an integer to be used as
enum. There's no advantage to store a number instead of an string if the
ammount of elements in the table is not going to be huge, or we can take
advantage of using an enum.

Also maintaining both Newsletters enum paired with UserSegments::SEGMENTS
would be a maintenance burden.

How:

* Migration to change segment_recipient column from integer to string
* Removing enumeration from Newsletter model class
* Using UserSegments::SEGMENTS instead of Newsletter.segment_recipients
or integer values
This commit is contained in:
Bertocq
2018-02-20 22:38:49 +01:00
parent bdbb32e824
commit 4becd0eb35
10 changed files with 25 additions and 23 deletions

View File

@@ -10,7 +10,7 @@ feature "Admin newsletter emails" do
scenario "Show" do
newsletter = create(:newsletter, subject: "This is a subject",
segment_recipient: 1,
segment_recipient: 'all_users',
from: "no-reply@consul.dev",
body: "This is a body")
@@ -116,14 +116,14 @@ feature "Admin newsletter emails" do
end
scenario "Select list of users to send newsletter" do
Newsletter.segment_recipients.each_key do |user_group|
UserSegments::SEGMENTS.each do |user_segment|
visit new_admin_newsletter_path
fill_in_newsletter_form
select I18n.t("admin.segment_recipient.#{user_group}"), from: 'newsletter_segment_recipient'
select I18n.t("admin.segment_recipient.#{user_segment}"), from: 'newsletter_segment_recipient'
click_button "Create Newsletter"
expect(page).to have_content(I18n.t("admin.segment_recipient.#{user_group}"))
expect(page).to have_content(I18n.t("admin.segment_recipient.#{user_segment}"))
end
end
end