Skip to content

Commit 31eca8b

Browse files
committed
Publish Moments/Strategies by default instead of draft
1 parent 7ae9d13 commit 31eca8b

10 files changed

+149
-27
lines changed

app/helpers/moments_form_helper.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def new_moment_props
1010
end
1111

1212
def edit_moment_props
13-
edit_form_props(moment_form_inputs, moment_path(@moment))
13+
edit_form_props(moment_form_inputs(true), moment_path(@moment))
1414
end
1515

1616
private
@@ -75,10 +75,11 @@ def moment_comment
7575
info: t('comment.hint'), dark: true)
7676
end
7777

78-
def moment_publishing
78+
def moment_publishing(edit)
7979
{ id: 'moment_publishing', type: 'switch',
8080
label: t('moments.form.draft_question'), dark: true, name: 'publishing',
81-
value: '0', uncheckedValue: '1', checked: !@moment.published? }
81+
value: '0', uncheckedValue: '1',
82+
checked: edit ? !@moment.published? : @moment.published? }
8283
end
8384

8485
def moment_bookmarked
@@ -97,12 +98,12 @@ def moment_display_resources
9798
checked: @moment.resource_recommendations, dark: true)
9899
end
99100

100-
def moment_form_inputs
101+
def moment_form_inputs(edit = false)
101102
[
102103
moment_name, moment_why, moment_fix, moment_category, moment_mood,
103104
moment_strategy, get_viewers_input(
104105
@viewers, 'moment', 'moments', @moment
105-
), moment_comment, moment_publishing,
106+
), moment_comment, moment_publishing(edit),
106107
Rails.env.development? ? moment_bookmarked : {}, moment_display_resources
107108
]
108109
end

app/helpers/strategies_form_helper.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ def build_strategy_comment(strategy)
6262
)
6363
end
6464

65-
def build_strategy_publishing(strategy)
66-
build_switch_input('0',
67-
params[:bookmarked] ? false : !strategy.published?, '1')
65+
def build_strategy_publishing(strategy, edit)
66+
checked = strategy.published?
67+
checked = !strategy.published? if edit
68+
checked = false if params[:bookmarked]
69+
70+
build_switch_input('0', checked, '1')
6871
.merge(
6972
id: 'strategy_publishing', name: 'publishing',
7073
label: t('strategies.form.draft_question')

app/helpers/strategies_helper.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ def quick_create_strategy_props
2121

2222
def edit_strategy_props(strategy, viewers)
2323
edit_form_props(
24-
strategy_form_inputs(strategy, viewers),
24+
strategy_form_inputs(strategy, viewers, true),
2525
strategy_path(strategy)
2626
)
2727
end
2828

2929
private
3030

31-
def strategy_form_inputs(strategy, viewers)
31+
def strategy_form_inputs(strategy, viewers, edit = false)
3232
[build_strategy_name(strategy), build_strategy_description(strategy),
3333
build_strategy_category,
3434
get_viewers_input(viewers, 'strategy', 'strategies', strategy),
35-
build_strategy_comment(strategy), build_strategy_publishing(strategy),
35+
build_strategy_comment(strategy),
36+
build_strategy_publishing(strategy, edit),
3637
build_strategy_visible(strategy),
3738
build_strategy_bookmarked(strategy),
3839
build_strategy_reminder(strategy).merge(type: 'checkbox'),

spec/features/user_creates_a_draft_moment_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
it 'is not successful' do
1212
login_as user
1313
visit new_moment_path
14+
find('#moment_publishing_switch').click
1415
find('#submit').click
1516
expect(page).to have_content('New Moment')
1617
expect(page).to have_css('.labelError')
@@ -85,6 +86,7 @@
8586
end
8687

8788
find('#moment_comment_switch').click
89+
find('#moment_publishing_switch').click
8890
find('#submit').click
8991

9092
# VIEWING AS OWNER

spec/features/user_creates_a_draft_strategy_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
it 'is not successful' do
1010
login_as user
1111
visit new_strategy_path
12+
find('#strategy_publishing_switch').click
1213
find('#submit').click
1314
expect(page).to have_content('New Strategy')
1415
expect(page).to have_css('.labelError')
@@ -55,6 +56,7 @@
5556

5657
find('#strategy_comment_switch').click
5758
find('#strategy_perform_strategy_reminder').click
59+
find('#strategy_publishing_switch').click
5860
find('#submit').click
5961

6062
# VIEWING

spec/features/user_creates_a_published_moment_spec.rb

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
it 'is not successful' do
1111
login_as user
1212
visit new_moment_path
13-
find('#moment_publishing_switch').click
1413
find('#submit').click
1514
expect(page).to have_content('New Moment')
1615
expect(page).to have_css('.labelError')
@@ -89,7 +88,6 @@
8988
end
9089

9190
find('#moment_comment_switch').click
92-
find('#moment_publishing_switch').click
9391
find('#submit').click
9492

9593
# VIEWING

spec/features/user_creates_a_published_strategy_spec.rb

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
it 'is not successful' do
99
login_as user
1010
visit new_strategy_path
11-
find('#strategy_publishing_switch').click
1211
find('#submit').click
1312
expect(page).to have_content('New Strategy')
1413
expect(page).to have_css('.labelError')
@@ -59,7 +58,6 @@
5958

6059
find('#strategy_comment_switch').click
6160
find('#strategy_perform_strategy_reminder').click
62-
find('#strategy_publishing_switch').click
6361
find('#submit').click
6462

6563
# VIEWING

spec/helpers/moments_form_helper_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
value: true
229229
},
230230
{
231-
checked: true,
231+
checked: false,
232232
dark: true,
233233
id: 'moment_publishing',
234234
label: 'Do you want to save your moment as draft?',
@@ -462,7 +462,7 @@
462462
value: true
463463
},
464464
{
465-
checked: true,
465+
checked: false,
466466
dark: true,
467467
id: 'moment_publishing',
468468
label: 'Do you want to save your moment as draft?',

spec/helpers/strategies_form_helper.spec.rb

+36-9
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@
114114
label: t('strategies.form.draft_question')
115115
)
116116
end
117+
let(:build_strategy_publishing_edit_res) do
118+
build_switch_input_strategy_publishing_res.merge(
119+
id: 'strategy_publishing',
120+
name: 'publishing',
121+
label: t('strategies.form.draft_question'),
122+
checked: !strategy.published?
123+
)
124+
end
117125
let(:build_strategy_bookmarked_res) do
118126
build_switch_input_strategy_bookmarked_res.merge(
119127
id: 'strategy_bookmarked',
@@ -136,7 +144,7 @@
136144
type: 'switch',
137145
value: '0',
138146
uncheckedValue: '1',
139-
checked: !strategy.published?,
147+
checked: strategy.published?,
140148
dark: true
141149
}
142150
end
@@ -214,18 +222,37 @@
214222
end
215223

216224
describe '#build_strategy_publishing' do
217-
subject { build_strategy_publishing(strategy) }
225+
context 'when edit is false' do
226+
subject { build_strategy_publishing(strategy, false) }
218227

219-
context 'when there are no custom URL params' do
220-
it 'builds correct object' do
221-
expect(subject).to eq(build_strategy_publishing_res)
228+
context 'when there are no custom URL params' do
229+
it 'builds correct object' do
230+
expect(subject).to eq(build_strategy_publishing_res)
231+
end
232+
end
233+
234+
context 'when there are custom URL params' do
235+
it 'builds correct object' do
236+
params[:bookmarked] = true
237+
expect(subject).to eq(build_strategy_publishing_res.merge(checked: false))
238+
end
222239
end
223240
end
224241

225-
context 'when there are custom URL params' do
226-
it 'builds correct object' do
227-
params[:bookmarked] = true
228-
expect(subject).to eq(build_strategy_publishing_res.merge(checked: false))
242+
context 'when edit is true' do
243+
subject { build_strategy_publishing(strategy, true) }
244+
245+
context 'when there are no custom URL params' do
246+
it 'builds correct object' do
247+
expect(subject).to eq(build_strategy_publishing_edit_res)
248+
end
249+
end
250+
251+
context 'when there are custom URL params' do
252+
it 'builds correct object' do
253+
params[:bookmarked] = true
254+
expect(subject).to eq(build_strategy_publishing_edit_res.merge(checked: false))
255+
end
229256
end
230257
end
231258
end

spec/helpers/strategies_helper_spec.rb

+91-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,96 @@
5050
}
5151
end
5252
let(:strategy_form_inputs_res) do
53+
[
54+
{
55+
id: 'strategy_name',
56+
type: 'text',
57+
name: 'strategy[name]',
58+
label: t('common.name'),
59+
value: strategy.name || nil,
60+
placeholder: t('strategies.form.name_hint'),
61+
required: true,
62+
dark: true
63+
},
64+
{
65+
id: 'strategy_description',
66+
type: 'textarea',
67+
name: 'strategy[description]',
68+
label: t('strategies.form.describe'),
69+
value: strategy.description || nil,
70+
required: true,
71+
dark: true
72+
},
73+
{
74+
id: 'strategy_category',
75+
type: 'quickCreate',
76+
name: 'strategy[category][]',
77+
label: t('categories.plural'),
78+
placeholder: t('common.form.search_by_keywords'),
79+
checkboxes: category_checkboxes,
80+
formProps: category_form_inputs_res
81+
},
82+
get_viewers_input(viewers, 'strategy', 'strategies', strategy),
83+
{
84+
id: 'strategy_comment',
85+
type: 'switch',
86+
name: 'strategy[comment]',
87+
label: t('comment.allow_comments'),
88+
value: true,
89+
uncheckedValue: false,
90+
checked: strategy.comment,
91+
info: t('comment.hint'),
92+
dark: true
93+
},
94+
{
95+
id: 'strategy_publishing',
96+
type: 'switch',
97+
label: t('strategies.form.draft_question'),
98+
dark: true,
99+
name: 'publishing',
100+
value: '0',
101+
uncheckedValue: '1',
102+
checked: strategy.published?
103+
},
104+
{ id: 'strategy_visible',
105+
type: 'switch',
106+
label: t('shared.stats.make_visible_in_stats'),
107+
dark: true,
108+
name: 'strategy[visible]',
109+
value: true,
110+
uncheckedValue: false,
111+
checked: strategy.visible
112+
},
113+
{
114+
checked: false,
115+
dark: true,
116+
id: 'strategy_bookmarked',
117+
info: 'Bookmarked strategies appear in your Care Plan', label: 'Bookmark this strategy?',
118+
name: 'strategy[bookmarked]',
119+
type: 'switch',
120+
uncheckedValue: false,
121+
value: true
122+
},
123+
{
124+
id: 'strategy_perform_strategy_reminder',
125+
type: 'checkbox',
126+
name: 'strategy[perform_strategy_reminder_attributes][active]',
127+
label: t('common.daily_reminder'),
128+
info: t('strategies.form.daily_reminder_hint'),
129+
value: true,
130+
uncheckedValue: false,
131+
checked: strategy&.perform_strategy_reminder&.active,
132+
dark: true
133+
},
134+
{
135+
id: 'strategy_perform_strategy_reminder_attributes_id',
136+
name: 'strategy[perform_strategy_reminder_attributes][id]',
137+
type: 'hidden',
138+
value: strategy&.perform_strategy_reminder&.id
139+
}
140+
]
141+
end
142+
let(:strategy_form_inputs_edit_res) do
53143
[
54144
{
55145
id: 'strategy_name',
@@ -177,7 +267,7 @@
177267
it 'returns correct props' do
178268
expect(subject).to eq(
179269
edit_form_props(
180-
strategy_form_inputs_res,
270+
strategy_form_inputs_edit_res,
181271
"/strategies/#{strategy.slug}"
182272
)
183273
)

0 commit comments

Comments
 (0)