Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better labels #72

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/guide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def latest_editable_edition
return Edition.new unless latest_edition

if latest_edition.published?
latest_edition.draft_copy
latest_edition.draft_copy.tap do |e|
e.update_type = "major"
end
else
latest_edition
end
Expand Down
6 changes: 3 additions & 3 deletions app/views/guides/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@


<fieldset class='update'>
<legend>Content</legend>
<legend>Change summary</legend>
<div class='form-group'>
<%= editions_form.label :update_type %>
<%= editions_form.error_list :update_type %>
<%= editions_form.select :update_type, [["Major", "major"], ["Minor", "minor"]], {}, {class: 'update-type-select input-md-12 form-control'} %>
</div>
<div class="form-group change-note-form-group">
<%= editions_form.label :change_note %>
<%= editions_form.label :change_note, "Public change note" %>
<%= editions_form.text_area :change_note, class: 'input-md-12 form-control', rows: 5 %>
</div>
</fieldset>

<fieldset class='publication'>
<legend>Publication</legend>
<legend>Actions</legend>
<div class='form-group'>
<%= f.submit "Save Draft", class: 'btn btn-success', name: :save_draft, data: disable_if_new_record(guide) %>
<%= f.submit "Save Draft and Preview", class: 'btn btn-default', name: :save_draft_and_preview, data: disable_if_new_record(guide) %>
Expand Down
19 changes: 9 additions & 10 deletions spec/features/guide_publishing_flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
require 'capybara/rails'

RSpec.describe "Taking a guide through the publishing process", type: :feature do

before do
allow_any_instance_of(GuidePublisher).to receive(:put_draft)
end

context "latest edition is published" do
let(:guide){ given_a_published_guide_exists title: "Standups" }
let!(:guide) { given_a_published_guide_exists title: "Standups" }

before do
it "should create a new draft edition when saving changes" do
publisher_double = double(:publisher)
expect(GuidePublisher).to receive(:new).with(guide: guide).and_return(publisher_double)
expect(publisher_double).to receive(:put_draft).once
end

it "should create a new draft edition when saving changes" do
visit guides_path
click_link "Create new edition"
the_form_should_be_prepopulated_with_title "Standups"
fill_in "Title", with: "Standup meetings"
fill_in "Public change note", with: "Be more specific in the title"
click_button "Save Draft"

guide.reload
Expand All @@ -29,14 +27,12 @@
expect(guide.latest_edition.title).to eq "Standup meetings"
end

it "has a new default empty change note" do
it "defaults to a major update and the new change note is empty" do
visit guides_path

click_link "Create new edition"
expect(find_field('Change note').value).to be_blank
expect(page).to have_select("Update type", selected: "Minor")

click_button "Save Draft"
expect(find_field("Public change note").value).to be_blank
expect(page).to have_select("Update type", selected: "Major")
end
end

Expand Down Expand Up @@ -69,6 +65,7 @@

visit edit_guide_path(guide)
fill_in "Title", with: "Updated Title"
fill_in "Public change note", with: "Update Title"
click_button "Save Draft"

the_form_should_be_prepopulated_with_title "Updated Title"
Expand All @@ -85,6 +82,7 @@

visit guides_path
click_link "Create new edition"
fill_in "Public change note", with: "Fix a typo"
click_button "Save Draft"

within ".alert" do
Expand Down Expand Up @@ -221,6 +219,7 @@
visit edit_guide_path(guide)
fill_in "Title", with: "Second Edition"
fill_in "Body", with: "## Hi"
fill_in "Public change note", with: "Better greeting"
click_button "Save Draft"
click_link "Changes"

Expand Down
2 changes: 1 addition & 1 deletion spec/features/guide_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ def fill_in_guide_form
fill_in "Body", with: "## First Edition Title"

select "Major", from: "Update type"
fill_in "Change note", with: "Change Note"
fill_in "Public change note", with: "Change Note"
end
end
10 changes: 8 additions & 2 deletions spec/models/guide_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,23 @@

describe "#latest_editable_edition" do
it "returns the latest edition if it's not published" do
guide = Guide.create(slug: "/service-manual/ediatble", editions: [Generators.valid_edition])
guide = Guide.create(slug: "/service-manual/editable", editions: [Generators.valid_edition])
expect(guide.latest_editable_edition).to eq guide.reload.latest_edition
end

it "returns an unsaved copy of the latest edition if the latter is published" do
guide = Guide.create(slug: "/service-manual/ediatble", editions: [Generators.valid_published_edition(title: "Agile Methodologies")])
guide = Guide.create(slug: "/service-manual/editable", editions: [Generators.valid_published_edition(title: "Agile Methodologies")])

expect(guide.latest_editable_edition).to be_a_new_record
expect(guide.latest_editable_edition.title).to eq "Agile Methodologies"
end

it "defaults to update_type 'major' for a new drafts" do
guide = Guide.create(slug: "/service-manual/editable", editions: [Generators.valid_published_edition(update_type: 'minor')])

expect(guide.latest_editable_edition.update_type).to eq "major"
end

it "returns a new edition for a guide with no latest edition" do
expect(Guide.new.latest_editable_edition).to be_a_new_record
end
Expand Down