Skip to content

Instantly share code, notes, and snippets.

@alanmaciel
Created February 26, 2018 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanmaciel/9b68d7456457157ab0320793d5bbc3ce to your computer and use it in GitHub Desktop.
Save alanmaciel/9b68d7456457157ab0320793d5bbc3ce to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe "Editing a movie" do
it "updates the movie and shows the movie's updated details" do
movie = Movie.create(movie_attributes)
visit movie_url(movie)
click_link 'Edit'
expect(current_path).to eq(edit_movie_path(movie))
expect(find_field('Title').value).to eq(movie.title)
fill_in 'Title', with: "Updated Movie Title"
click_button 'Update Movie'
expect(current_path).to eq(movie_path(movie))
expect(page).to have_text('Updated Movie Title')
expect(page).to have_text('Movie successfully updated!')
end
it "does not update the movie if it's invalid" do
movie = Movie.create(movie_attributes)
visit edit_movie_url(movie)
fill_in 'Title', with: " "
click_button 'Update Movie'
expect(page).to have_text('error')
end
it "has many reviews" do
movie = Movie.new(movie_attributes)
review1 = movie.reviews.new(review_attributes)
review2 = movie.reviews.new(review_attributes)
expect(movie.reviews).to include(review1)
expect(movie.reviews).to include(review2)
end
it "deletes associated reviews" do
movie = Movie.create(movie_attributes)
movie.reviews.create(review_attributes)
expect {
movie.destroy
}.to change(Review, :count).by(-1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment