Ruby on Rails 5, Rspec 3.8, test environment destroy function acts as the show function
I am following the restaurantly Rails tutorial while making my own changes whenever I run into version (mostly syntax) issues between Rails version 4 and the Rails version 5 that I am using.
After completing the steps through this page on the tutorial I thought it was another syntax difference after my test failed for the destroy function.
rspec spec/features/restaurants_spec.rb
Capybara starting Puma...
* Version 3.12.0 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:41471
.F
Failures:
1) destroy links work displays Restaurantly Spots!
Failure/Error: expect(page).to have_no_content 'mc ruby'
expected not to find text "mc ruby" in "mc ruby"
# ./spec/features/restaurants_spec.rb:27:in `block (3 levels) in <top (required)>'
Finished in 7.25 seconds (files took 2.24 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/features/restaurants_spec.rb:20 # destroy links work displays Restaurantly Spots!
I ran puma -e 'test' to manually run the application in the "test" environment and in the browser step through the controller actions myself. I found that I got the same failed behaviour. All my defined actions including, create, edit, update, and show worked as expected. However destroy acted like show and simply displayed the show page for the item instead or redirecting to the root and deleting the item.
This all works as expected if I run rails server in the "development" environment including the destroy function.
Here are some different parts of my application in case it helps:
app/controllers/restaurants_controller.rb:
def destroy
@restaurant = Restaurant.find_by_id params[:id]
@restaurant.destroy
redirect_to root_path
end
app/views/restaurants/index.html.haml
.row
.large-8.columns.large-centered
%h3.subheader.center
Restaurantly Spots!
.row
.large-8-columns.large-centered
- @restaurants.each do |restaurant|
%h5.subheader
= restaurant.name
= link_to "edit", edit_restaurant_path(restaurant)
= link_to "destroy", restaurant_path(restaurant), method: :destroy
Part of my Gemfile that including the the development, test gems:
group :test, :development do
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'capybara'
gem 'pry'
gem 'pry-byebug'
end
I dropped the test database at one point and then created it again. I did this the same way I created it originally along with the development database by running bundle exec rake db:create, then bundle exec rake db:migrate and lastly bundle exec rake db:test:prepare.
config/database.yml
development:
adapter: postgresql
encoding: unicode
database: restaurantly_dev
pool: 5
host: ""
timeout: 5432
test:
adapter: postgresql
encoding: unicode
database: restaurantly_test
pool: 5
host: ""
timeout: 5432
Any ideas why it behaves differently for just the destroy function between the development and the test environment?
ruby-on-rails rspec-rails puma
add a comment |
I am following the restaurantly Rails tutorial while making my own changes whenever I run into version (mostly syntax) issues between Rails version 4 and the Rails version 5 that I am using.
After completing the steps through this page on the tutorial I thought it was another syntax difference after my test failed for the destroy function.
rspec spec/features/restaurants_spec.rb
Capybara starting Puma...
* Version 3.12.0 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:41471
.F
Failures:
1) destroy links work displays Restaurantly Spots!
Failure/Error: expect(page).to have_no_content 'mc ruby'
expected not to find text "mc ruby" in "mc ruby"
# ./spec/features/restaurants_spec.rb:27:in `block (3 levels) in <top (required)>'
Finished in 7.25 seconds (files took 2.24 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/features/restaurants_spec.rb:20 # destroy links work displays Restaurantly Spots!
I ran puma -e 'test' to manually run the application in the "test" environment and in the browser step through the controller actions myself. I found that I got the same failed behaviour. All my defined actions including, create, edit, update, and show worked as expected. However destroy acted like show and simply displayed the show page for the item instead or redirecting to the root and deleting the item.
This all works as expected if I run rails server in the "development" environment including the destroy function.
Here are some different parts of my application in case it helps:
app/controllers/restaurants_controller.rb:
def destroy
@restaurant = Restaurant.find_by_id params[:id]
@restaurant.destroy
redirect_to root_path
end
app/views/restaurants/index.html.haml
.row
.large-8.columns.large-centered
%h3.subheader.center
Restaurantly Spots!
.row
.large-8-columns.large-centered
- @restaurants.each do |restaurant|
%h5.subheader
= restaurant.name
= link_to "edit", edit_restaurant_path(restaurant)
= link_to "destroy", restaurant_path(restaurant), method: :destroy
Part of my Gemfile that including the the development, test gems:
group :test, :development do
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'capybara'
gem 'pry'
gem 'pry-byebug'
end
I dropped the test database at one point and then created it again. I did this the same way I created it originally along with the development database by running bundle exec rake db:create, then bundle exec rake db:migrate and lastly bundle exec rake db:test:prepare.
config/database.yml
development:
adapter: postgresql
encoding: unicode
database: restaurantly_dev
pool: 5
host: ""
timeout: 5432
test:
adapter: postgresql
encoding: unicode
database: restaurantly_test
pool: 5
host: ""
timeout: 5432
Any ideas why it behaves differently for just the destroy function between the development and the test environment?
ruby-on-rails rspec-rails puma
What does the test look like? Also,methodshould be:deletenot:destroy(it's the name of the REST request METHOD (GET POST DELETE PATCH etc), not the method/action name. And also, Rails uses javascript to turn links withmethod: :deletein DELETE requests, so a link to delete won't work if you don't support javascript on your test driver.
– arieljuod
Nov 25 '18 at 22:56
add a comment |
I am following the restaurantly Rails tutorial while making my own changes whenever I run into version (mostly syntax) issues between Rails version 4 and the Rails version 5 that I am using.
After completing the steps through this page on the tutorial I thought it was another syntax difference after my test failed for the destroy function.
rspec spec/features/restaurants_spec.rb
Capybara starting Puma...
* Version 3.12.0 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:41471
.F
Failures:
1) destroy links work displays Restaurantly Spots!
Failure/Error: expect(page).to have_no_content 'mc ruby'
expected not to find text "mc ruby" in "mc ruby"
# ./spec/features/restaurants_spec.rb:27:in `block (3 levels) in <top (required)>'
Finished in 7.25 seconds (files took 2.24 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/features/restaurants_spec.rb:20 # destroy links work displays Restaurantly Spots!
I ran puma -e 'test' to manually run the application in the "test" environment and in the browser step through the controller actions myself. I found that I got the same failed behaviour. All my defined actions including, create, edit, update, and show worked as expected. However destroy acted like show and simply displayed the show page for the item instead or redirecting to the root and deleting the item.
This all works as expected if I run rails server in the "development" environment including the destroy function.
Here are some different parts of my application in case it helps:
app/controllers/restaurants_controller.rb:
def destroy
@restaurant = Restaurant.find_by_id params[:id]
@restaurant.destroy
redirect_to root_path
end
app/views/restaurants/index.html.haml
.row
.large-8.columns.large-centered
%h3.subheader.center
Restaurantly Spots!
.row
.large-8-columns.large-centered
- @restaurants.each do |restaurant|
%h5.subheader
= restaurant.name
= link_to "edit", edit_restaurant_path(restaurant)
= link_to "destroy", restaurant_path(restaurant), method: :destroy
Part of my Gemfile that including the the development, test gems:
group :test, :development do
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'capybara'
gem 'pry'
gem 'pry-byebug'
end
I dropped the test database at one point and then created it again. I did this the same way I created it originally along with the development database by running bundle exec rake db:create, then bundle exec rake db:migrate and lastly bundle exec rake db:test:prepare.
config/database.yml
development:
adapter: postgresql
encoding: unicode
database: restaurantly_dev
pool: 5
host: ""
timeout: 5432
test:
adapter: postgresql
encoding: unicode
database: restaurantly_test
pool: 5
host: ""
timeout: 5432
Any ideas why it behaves differently for just the destroy function between the development and the test environment?
ruby-on-rails rspec-rails puma
I am following the restaurantly Rails tutorial while making my own changes whenever I run into version (mostly syntax) issues between Rails version 4 and the Rails version 5 that I am using.
After completing the steps through this page on the tutorial I thought it was another syntax difference after my test failed for the destroy function.
rspec spec/features/restaurants_spec.rb
Capybara starting Puma...
* Version 3.12.0 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:41471
.F
Failures:
1) destroy links work displays Restaurantly Spots!
Failure/Error: expect(page).to have_no_content 'mc ruby'
expected not to find text "mc ruby" in "mc ruby"
# ./spec/features/restaurants_spec.rb:27:in `block (3 levels) in <top (required)>'
Finished in 7.25 seconds (files took 2.24 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/features/restaurants_spec.rb:20 # destroy links work displays Restaurantly Spots!
I ran puma -e 'test' to manually run the application in the "test" environment and in the browser step through the controller actions myself. I found that I got the same failed behaviour. All my defined actions including, create, edit, update, and show worked as expected. However destroy acted like show and simply displayed the show page for the item instead or redirecting to the root and deleting the item.
This all works as expected if I run rails server in the "development" environment including the destroy function.
Here are some different parts of my application in case it helps:
app/controllers/restaurants_controller.rb:
def destroy
@restaurant = Restaurant.find_by_id params[:id]
@restaurant.destroy
redirect_to root_path
end
app/views/restaurants/index.html.haml
.row
.large-8.columns.large-centered
%h3.subheader.center
Restaurantly Spots!
.row
.large-8-columns.large-centered
- @restaurants.each do |restaurant|
%h5.subheader
= restaurant.name
= link_to "edit", edit_restaurant_path(restaurant)
= link_to "destroy", restaurant_path(restaurant), method: :destroy
Part of my Gemfile that including the the development, test gems:
group :test, :development do
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'capybara'
gem 'pry'
gem 'pry-byebug'
end
I dropped the test database at one point and then created it again. I did this the same way I created it originally along with the development database by running bundle exec rake db:create, then bundle exec rake db:migrate and lastly bundle exec rake db:test:prepare.
config/database.yml
development:
adapter: postgresql
encoding: unicode
database: restaurantly_dev
pool: 5
host: ""
timeout: 5432
test:
adapter: postgresql
encoding: unicode
database: restaurantly_test
pool: 5
host: ""
timeout: 5432
Any ideas why it behaves differently for just the destroy function between the development and the test environment?
ruby-on-rails rspec-rails puma
ruby-on-rails rspec-rails puma
asked Nov 25 '18 at 21:53
TheBrianGuyTheBrianGuy
1015
1015
What does the test look like? Also,methodshould be:deletenot:destroy(it's the name of the REST request METHOD (GET POST DELETE PATCH etc), not the method/action name. And also, Rails uses javascript to turn links withmethod: :deletein DELETE requests, so a link to delete won't work if you don't support javascript on your test driver.
– arieljuod
Nov 25 '18 at 22:56
add a comment |
What does the test look like? Also,methodshould be:deletenot:destroy(it's the name of the REST request METHOD (GET POST DELETE PATCH etc), not the method/action name. And also, Rails uses javascript to turn links withmethod: :deletein DELETE requests, so a link to delete won't work if you don't support javascript on your test driver.
– arieljuod
Nov 25 '18 at 22:56
What does the test look like? Also,
method should be :delete not :destroy (it's the name of the REST request METHOD (GET POST DELETE PATCH etc), not the method/action name. And also, Rails uses javascript to turn links with method: :delete in DELETE requests, so a link to delete won't work if you don't support javascript on your test driver.– arieljuod
Nov 25 '18 at 22:56
What does the test look like? Also,
method should be :delete not :destroy (it's the name of the REST request METHOD (GET POST DELETE PATCH etc), not the method/action name. And also, Rails uses javascript to turn links with method: :delete in DELETE requests, so a link to delete won't work if you don't support javascript on your test driver.– arieljuod
Nov 25 '18 at 22:56
add a comment |
1 Answer
1
active
oldest
votes
Thanks @arieljuod for pointing out that I had the method as :destroy when it should have been :delete. I may have added that by accident during my troubleshooting so I can't say that was the issue all along. Especially because the delete function was working in the development environment and not the test environment. However I was then getting a routing error after I made the change which I had not seen before and it was still trying to POST instead of DELETE.
I read this answer and found that after removing //= require jquery2//= require jquery_ujs
andfrom theapplication.css` file that all seemed to be working fine in both production and test. I don't know why those were there or why it corrected the issue. My feature tests now pass as well.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472368%2fruby-on-rails-5-rspec-3-8-test-environment-destroy-function-acts-as-the-show-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks @arieljuod for pointing out that I had the method as :destroy when it should have been :delete. I may have added that by accident during my troubleshooting so I can't say that was the issue all along. Especially because the delete function was working in the development environment and not the test environment. However I was then getting a routing error after I made the change which I had not seen before and it was still trying to POST instead of DELETE.
I read this answer and found that after removing //= require jquery2//= require jquery_ujs
andfrom theapplication.css` file that all seemed to be working fine in both production and test. I don't know why those were there or why it corrected the issue. My feature tests now pass as well.
add a comment |
Thanks @arieljuod for pointing out that I had the method as :destroy when it should have been :delete. I may have added that by accident during my troubleshooting so I can't say that was the issue all along. Especially because the delete function was working in the development environment and not the test environment. However I was then getting a routing error after I made the change which I had not seen before and it was still trying to POST instead of DELETE.
I read this answer and found that after removing //= require jquery2//= require jquery_ujs
andfrom theapplication.css` file that all seemed to be working fine in both production and test. I don't know why those were there or why it corrected the issue. My feature tests now pass as well.
add a comment |
Thanks @arieljuod for pointing out that I had the method as :destroy when it should have been :delete. I may have added that by accident during my troubleshooting so I can't say that was the issue all along. Especially because the delete function was working in the development environment and not the test environment. However I was then getting a routing error after I made the change which I had not seen before and it was still trying to POST instead of DELETE.
I read this answer and found that after removing //= require jquery2//= require jquery_ujs
andfrom theapplication.css` file that all seemed to be working fine in both production and test. I don't know why those were there or why it corrected the issue. My feature tests now pass as well.
Thanks @arieljuod for pointing out that I had the method as :destroy when it should have been :delete. I may have added that by accident during my troubleshooting so I can't say that was the issue all along. Especially because the delete function was working in the development environment and not the test environment. However I was then getting a routing error after I made the change which I had not seen before and it was still trying to POST instead of DELETE.
I read this answer and found that after removing //= require jquery2//= require jquery_ujs
andfrom theapplication.css` file that all seemed to be working fine in both production and test. I don't know why those were there or why it corrected the issue. My feature tests now pass as well.
answered Nov 26 '18 at 4:16
TheBrianGuyTheBrianGuy
1015
1015
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472368%2fruby-on-rails-5-rspec-3-8-test-environment-destroy-function-acts-as-the-show-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does the test look like? Also,
methodshould be:deletenot:destroy(it's the name of the REST request METHOD (GET POST DELETE PATCH etc), not the method/action name. And also, Rails uses javascript to turn links withmethod: :deletein DELETE requests, so a link to delete won't work if you don't support javascript on your test driver.– arieljuod
Nov 25 '18 at 22:56