Skip to content

Commit

Permalink
fixed schema and tests for n:m, solved #29
Browse files Browse the repository at this point in the history
  • Loading branch information
akuchinke committed Nov 9, 2017
1 parent 3207d83 commit 8bc1a15
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/controllers/authors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ def new

def edit
@author = Author.find(params[:id])

end


def create
@author = Author.new(author_params)

if @author.save
redirect_to @author
else
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def show

def new
@paper = Paper.new

end

def edit
Expand All @@ -18,6 +19,7 @@ def edit

def create
@paper = Paper.new(paper_params)
@paper.authors=[]

if @paper.save
redirect_to @paper
Expand Down
5 changes: 4 additions & 1 deletion db/migrate/20171109193956_join_papers_and_authors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class JoinPapersAndAuthors < ActiveRecord::Migration
def change
create_join_table :authors, :papers
create_join_table :authors, :papers do |t|
t.index [:author_id, :paper_id]
t.index [:paper_id, :author_id]
end
end
end
3 changes: 3 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
t.integer "paper_id", null: false
end

add_index "authors_papers", ["author_id", "paper_id"], name: "index_authors_papers_on_author_id_and_paper_id"
add_index "authors_papers", ["paper_id", "author_id"], name: "index_authors_papers_on_paper_id_and_author_id"

create_table "papers", force: :cascade do |t|
t.string "title"
t.string "venue"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/authors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
last_name "Turing"
homepage "http://wikipedia.de/Alan_Turing"
id "1"

end
end
6 changes: 6 additions & 0 deletions spec/models/author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

end

it "have papers" do
author = Author.new()
expect(author.papers).to be_empty

end



end
5 changes: 5 additions & 0 deletions spec/models/paper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@

end

it "Should have authors" do
paper=Paper.new()
expect(paper.authors).to be_empty
end

end

0 comments on commit 8bc1a15

Please sign in to comment.