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

Controller specs #5

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ gem 'bootsnap', require: false
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'rails-controller-testing'
gem 'rspec-rails'
end

Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ GEM
activesupport (= 7.0.8)
bundler (>= 1.15.0)
railties (= 7.0.8)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
Expand Down Expand Up @@ -265,6 +269,7 @@ DEPENDENCIES
pg (~> 1.1)
puma (~> 5.0)
rails (~> 7.0.8)
rails-controller-testing
rspec-rails
rubocop (>= 1.0, < 2.0)
selenium-webdriver
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h1>This pages shows the users list</h1>
<h1>This page shows the users list</h1>
2 changes: 1 addition & 1 deletion spec/helpers/posts_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
# end
# end
RSpec.describe PostsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
# pending "add some examples to (or delete) #{__FILE__}"
end
2 changes: 1 addition & 1 deletion spec/helpers/users_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
# end
# end
RSpec.describe UsersHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
# pending "add some examples to (or delete) #{__FILE__}"
end
22 changes: 19 additions & 3 deletions spec/requests/posts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,32 @@

RSpec.describe 'Posts', type: :request do
describe 'GET /index' do
it 'returns http success' do
get '/posts/index'
it 'returns http success for Posts index page' do
get '/users/:user_id/posts'
expect(response).to have_http_status(:success)
end
it 'renders the index template for posts' do
get '/users/:user_id/posts'
expect(response).to render_template(:index)
end
it 'Response Body includes correct placeholder text' do
get '/users/:user_id/posts'
expect(response.body).to include('Show posts related to user ID')
end
end

describe 'GET /show' do
it 'returns http success' do
get '/posts/show'
get '/users/:user_id/posts/:id'
expect(response).to have_http_status(:success)
end
it 'renders the index template for posts' do
get '/users/:user_id/posts/:id'
expect(response).to render_template(:show)
end
it 'Response Body includes correct placeholder text' do
get '/users/:user_id/posts/:id'
expect(response.body).to include('Show user post with specific Id')
end
end
end
29 changes: 26 additions & 3 deletions spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
require 'rails_helper'

RSpec.describe 'Users', type: :request do
describe 'GET /index' do
it 'returns http success' do
get '/users/index'
describe 'GET /Index' do
it 'returns http success for Users index page' do
get '/users'
expect(response).to have_http_status(:success)
end
it 'renders the index template for users' do
get '/users'
expect(response).to render_template(:index)
end
it 'Response Body includes correct placeholder text' do
get '/users'
expect(response.body).to include('This page shows the users list')
end
end

describe 'GET /show' do
it 'returns http success for users show page' do
get '/users/:id'
expect(response).to have_http_status(:success)
end
it 'renders the show template for users' do
get '/users/:id'
expect(response).to render_template(:show)
end
it 'Response Body includes correct placeholder text' do
get '/users/:id'
expect(response.body).to include('Show Users with Id')
end
end
end
2 changes: 1 addition & 1 deletion spec/views/posts/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rails_helper'

RSpec.describe 'posts/index.html.erb', type: :view do
pending "add some examples to (or delete) #{__FILE__}"
# pending "add some examples to (or delete) #{__FILE__}"
end
2 changes: 1 addition & 1 deletion spec/views/posts/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rails_helper'

RSpec.describe 'posts/show.html.erb', type: :view do
pending "add some examples to (or delete) #{__FILE__}"
# pending "add some examples to (or delete) #{__FILE__}"
end
2 changes: 1 addition & 1 deletion spec/views/users/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rails_helper'

RSpec.describe 'users/index.html.erb', type: :view do
pending "add some examples to (or delete) #{__FILE__}"
# pending "add some examples to (or delete) #{__FILE__}"
end
Loading