Skip to content

Commit

Permalink
added test and author selects for dit papers page, solved #31
Browse files Browse the repository at this point in the history
  • Loading branch information
akuchinke committed Nov 9, 2017
1 parent d73fa9a commit 375a0a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/authors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def show
end

def new
@author = Author.new()
@author = Author.new
end

def edit
Expand Down
26 changes: 26 additions & 0 deletions app/views/papers/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@

<p><strong>Edit paper</strong></p>
<%= form_for :paper, url: paper_path(@paper), method: :patch do |f| %>
<% if @paper.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@paper.errors.count, "error") %> prohibited
this author from being saved:
</h2>
<ul>
<% @paper.errors.full_messages.each do |msg| %>
<li><%=msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
Expand All @@ -14,8 +27,21 @@
<%= f.label :year %><br>
<%= f.text_field :year %>
</p>
<% for i in 1..5 do %>
<p>
<%= f.label "Author #" + i.to_s, for: "paper_author_id_" + i.to_s %>
<%= f.collection_select :author_ids,
Author.all,
:id,
:name,
{selected: @paper.author_ids[i], include_blank: '(none)'},
{name: "paper[author_ids][]", id: "paper_author_id_" + i.to_s} %>
</p>
<% end %>

<p>
<%= f.submit %>
</p>


<% end %>
2 changes: 1 addition & 1 deletion app/views/papers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@

<p><strong>Authors:</strong></p>
<% @paper.authors.each do |author| %>
<p><%= author.first_name %> <%= author.last_name %></p>
<p><%= author.name %></p>
<% end %>
6 changes: 6 additions & 0 deletions spec/features/paper/edit_paper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe "Edit paper page", type: :feature do
before do
@paper = create :paper
@paper2 = create :paper_with_author
end
it "Should render" do
visit edit_paper_path(@paper)
Expand All @@ -15,6 +16,11 @@
expect(page).to have_content('A new Title')
end

it "Show authors" do
visit edit_paper_path(@paper2)
expect(page).to have_content('Alan')
end



end

0 comments on commit 375a0a4

Please sign in to comment.