generated from appdev-projects/helper-methods-v1
-
Notifications
You must be signed in to change notification settings - Fork 63
Adding specs (mostly refactoring of helper-methods) #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ea1313f
added helper-methods specs
bpurinton 81e2d2f
remove authenticity_token spec
bpurinton d813134
added some card and font awesome specs
bpurinton 5020e80
added spec for navbar
bpurinton a4ad5b4
added spec for container
bpurinton c958baf
remove before blocks
bpurinton 76d72b5
basic devise spec
bpurinton 9c81efb
PR comment light-themed bootstrap
bpurinton 63270ce
PR comment margin top spacing
bpurinton a84423f
PR comment create movie
bpurinton 73f299f
devise sign up and sign in specs
bpurinton fc7c0f9
better devise testing
bpurinton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
require "rails_helper" | ||
|
||
describe "User authentication" do | ||
it "requires sign in before any action with the Devise `before_action :authenticate_user!` method", points: 2 do | ||
visit "/movies/new" | ||
current_url = page.current_path | ||
|
||
expect(current_url).to eq(new_user_session_path), | ||
"Expected `before_action :authenticate_user!` in `ApplicationController` to redirect guest to /users/sign_in before visiting another page." | ||
end | ||
|
||
it "allows a user to sign up", points: 2 do | ||
old_users_count = User.count | ||
visit new_user_registration_path | ||
|
||
fill_in "Email", with: "user@example.com" | ||
fill_in "Password", with: "password" | ||
fill_in "Password confirmation", with: "password" | ||
click_button "Sign up" | ||
|
||
new_users_count = User.count | ||
|
||
expect(old_users_count).to be < new_users_count, | ||
"Expected 'Sign up' form on /users/sign_up to successfully add a User record to the database." | ||
end | ||
end | ||
|
||
describe "The /movies page" do | ||
before do | ||
sign_in_user if user_model_exists? | ||
end | ||
|
||
it "can be visited", points: 1 do | ||
visit "/movies" | ||
|
||
expect(page.status_code).to be(200), | ||
"Expected to visit /movies successfully." | ||
end | ||
|
||
it "has a link to add a movie", points: 1 do | ||
visit "/movies" | ||
|
||
expect(page).to have_link('Add a new movie', href: "/movies/new"), | ||
"Expected /movies to have an 'Add a new movie' link to '/movies/new'." | ||
end | ||
|
||
it "has a large, light-themed bootstrap navbar", points: 1 do | ||
visit "/movies" | ||
|
||
expect(page).to have_selector("nav[class='navbar navbar-expand-lg navbar-light bg-light']"), | ||
jelaniwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Expected /movies to have have a <nav class='navbar navbar-expand-lg navbar-light bg-light'> bootstrap navbar." | ||
end | ||
|
||
it "has margin top spacing with a bootstrap container class", points: 1 do | ||
visit "/movies" | ||
|
||
expect(page).to have_selector("div[class='container mt-3']"), | ||
"Expected /movies to have have a <div class='container mt-3'> bootstrap container for adding margin top spacing." | ||
end | ||
end | ||
|
||
describe "The /movies/new page" do | ||
before do | ||
sign_in_user if user_model_exists? | ||
end | ||
|
||
it "can be visited", points: 1 do | ||
visit "/movies/new" | ||
|
||
expect(page.status_code).to be(200), | ||
"Expected to visit /movies/new successfully." | ||
end | ||
|
||
it "has a form", points: 1 do | ||
visit "/movies/new" | ||
|
||
expect(page).to have_selector("form[action='/movies']"), | ||
"Expected /movies/new to have a form with action='/movies'." | ||
end | ||
|
||
it "has a form that creates a movie record", point: 1 do | ||
old_movies_count = Movie.count | ||
visit "/movies/new" | ||
|
||
fill_in "Title", with: "My test movie" | ||
fill_in "Description", with: "description" | ||
click_button "Create Movie" | ||
|
||
new_movies_count = Movie.count | ||
|
||
expect(old_movies_count).to be < new_movies_count, | ||
"Expected 'Create Movie' form on /movies/new to successfully add a Movie record to the database." | ||
end | ||
|
||
it "displays a success notice flash message after creating movie", point: 1 do | ||
visit "/movies/new" | ||
|
||
fill_in "Title", with: "My test movie" | ||
fill_in "Description", with: "description" | ||
click_button "Create Movie" | ||
|
||
expect(page).to have_content("Movie created successfully."), | ||
"Expected to see the notice flash message 'Movie created successfully' after filling in and submitting the /movies/new form." | ||
end | ||
end | ||
|
||
describe "The movie details page" do | ||
let(:movie) { Movie.create(title: "My title", description: "My description") } | ||
|
||
before do | ||
sign_in_user if user_model_exists? | ||
end | ||
|
||
it "can be visited", points: 1 do | ||
visit "/movies/#{movie.id}" | ||
|
||
expect(page.status_code).to be(200), | ||
"Expected to visit /movies/ID successfully." | ||
end | ||
|
||
it "shows the movie on a bootstrap card", points: 2 do | ||
visit "/movies/#{movie.id}" | ||
|
||
expect(page).to have_selector("div[class='card']"), | ||
"Expected /movies/ID to have have a <div class='card'> element to display the movie." | ||
end | ||
|
||
it "has a Font Awesome trash can icon to delete the movie", points: 2 do | ||
visit "/movies/#{movie.id}" | ||
|
||
expect(page).to have_selector("i[class='fa-regular fa-trash-can']"), | ||
"Expected /movies/ID to have a Font Awesome trash can icon on the card, with class='fa-regular fa-trash-can'." | ||
end | ||
|
||
it "deletes the movie with a DELETE request", points: 2 do | ||
visit "/movies/#{movie.id}" | ||
|
||
expect(page).to have_selector("a[href='/movies/#{movie.id}'][data-method='delete']"), | ||
"Expected /movies/ID to have 'Delete Movie' link with the proper data-method='delete'." | ||
end | ||
end | ||
|
||
describe "The movie edit page" do | ||
let(:movie) { Movie.create(title: "My title", description: "My description") } | ||
|
||
before do | ||
sign_in_user if user_model_exists? | ||
end | ||
|
||
it "can be visited", points: 1 do | ||
visit "/movies/#{movie.id}/edit" | ||
|
||
expect(page.status_code).to be(200), | ||
"Expected to visit /movies/ID/edit successfully." | ||
end | ||
|
||
it "has a form", points: 1 do | ||
visit "/movies/#{movie.id}/edit" | ||
|
||
expect(page).to have_selector("form[action='/movies/#{movie.id}'][method='post']"), | ||
"Expected /movies/ID/edit to have a form with action='/movies/ID' and method='post'." | ||
end | ||
|
||
it "has a hidden patch input", points: 2 do | ||
visit "/movies/#{movie.id}/edit" | ||
|
||
expect(page).to have_selector("input[name='_method'][value='patch']", visible: false), | ||
"Expected the edit movie form to have an input field of type='hidden' with name='_method' and value='patch'." | ||
end | ||
end | ||
|
||
|
||
def sign_in_user | ||
user = User.create(email: "alice@example.com", password: "password") | ||
visit new_user_session_path | ||
|
||
fill_in "Email", with: user.email | ||
fill_in "Password", with: user.password | ||
click_button "Log in" | ||
end | ||
|
||
def user_model_exists? | ||
Object.const_defined?("User") | ||
end |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Devise isn't installed this will fail since

new_user_session_path
isn't defined. That won't make the custom error message display though, since the expectation never ran.If your intention was that the custom error message would be visible to students who haven't created users, then you should use the String path instead. Something like:
I also buy the idea that since the spec title already mentions Devise, student could infer that they need devise to make the test pass w/out the help of the error message. It's up to you if you want to make this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I considered my use of the helper method there, but that's why I include Devise in the spec. The assumption is that they should have added devise and installed it, which will provide those helper methods.
Merging! Thanks for all your help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember now that students tend to work top down from the list of specs, so placing the Devise-required specs at the bottom will probably eliminate some friction. It's not a big deal though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sure. Just going to make that change directly on main.