How to make Sinatra sessions persist across POSTs in tests? - ruby

In the following code from Learn Ruby the Hard Way : https://gist.github.com/1696733 the session seems to disappear after going through the 'post' in tests (run ruby test_gothonweb.rb to see what I mean). If I actually visit the site with my browser everything works correctly, but I would like to be able to test the site without visiting every page. What are the possible reasons for the sessions disappearing in tests?
There are a few questions coming close to this problem, but most of them are solved by not using shotgun. I am not using shotgun. I am just using regular ruby.
Versions:
ruby: 1.9.2
sinatra : 1.3.2
rack: 1.4.0 1.4.1
rack-test: 0.6.1
EDIT
I am also disabling the sessions while testing as per http://benprew.posterous.com/testing-sessions-with-sinatra - the first test using sessions with GET does work in that case (but not the POST one).

There is a known issue with rack 1.4.0. Update the gem to 1.4.1

Related

Getting Paperclip::AdapterRegistry::NoHandlerError when using Padrino

I've been getting an issue where when using Padrino and paperclip whenever I try to upload an image I get the error
Paperclip::AdapterRegistry::NoHandlerError
What's going wrong?
For those wondering, the multipart form thing mentioned in many other posts is also true. See Other SO posts
All of those relate to Rails and specifically if you are using Padrino or another rack based application, you need to add one more thing or else it won't work
The exception being thrown was due to the uploaded file being represented by a Hash (Rack converts it into a Hash), and that Paperclip does not provide an adapter for this Rack specific Hash out of the box.
You need to install this gem:
gem 'paperclip-rack', require: 'paperclip/rack'

Rails 4.2.0 + passenger + apache + Custom Engines - how to reload properly?

I'm deploying rails 4.2.0 app with passenger5 and apache2 on Ubuntu12.04 server.
When I pull the new version of the app from github I need to reload the app for changes to come into effect.
My custom Engines are 'required' in the Gemfile as proposed in the Rails Guide
gem 'CustomeEngine', path: "lib/engines/CustomeEngine"
Based on passenger Documentation we can reload the web server by creating this file:
touch ${MYAPP}/tmp/restart.txt
When I make changes in CustomeEngine's code Rails seems not to reload the CustomeEngine with the restart.txt methode.
Please help me understand how to reload rails properly.
Best answer for me would be how do I do this in 'one line' of bash. Pull changes from github and reload the App which is running inside of a passenger process.
Thank you in advance!

Rails, production environment exception page shows in development environment

I'm running Rails 4.2.0.beta and am having a weird issue; instead of the usual Rail’s page displaying exceptions in development mode, like so:
I get the following:
This page appears with any exception.
I have double checked that I'm under development mode and that 'consider_all_requests_local' is set to true in config/environments/development.rb.
I noticed I'm receiving the following error when I hit an exception
" ERROR Rack::Lint::LintError: Response body was given for HEAD request, but should be empty
/Users/Rali/.rbenv/versions/2.2.0-dev/lib/ruby/gems/2.2.0/gems/rack-1.6.0.beta/lib/rack/lint.rb:20:in `assert'"
I assume it's somehow related.. Any ideas?
Sorry for digging out a month-old question but if there is anyone with same issue (like me), though with version 4.2.0.rc1 I fixed it by removing gem 'web-console' from Gemfile which is by default added when generating new application.
Removing gem 'web-console' also solved this issue for me in Rails 5.1, for anyone stumbling into this issue 4 years later...

Sinatra always prints '!! Invalid request" on standard output

I was messing around and recklessly trying to implement SSL with Sinatra. I was using many scripts that I found on the internet without actually knowing what they did. I then realized I didn't actually need SSL and now sinatra is completely broken.
No matter what my app is, it always always prints "!! Invalid request" on the terminal whenever it receives a request from the browser. I've noticed that the http://localhost:4567 always switches to https://localhost:4567 in the browser URL.
I would like to have Sinatra act like it did when I originally installed it.
I'm new to this...
Uninstall & reinstall Sinatra and Ruby

twitter gem not working in heroku?

I'm working on a ruby app that updates a twitter account using 'twitter' gem. It's working fine locally (as usual :) ). But when I deploy it on heroku it seems the gem is not properly installed or something lile that as I got the following error:
NameError: uninitialized constant Twitter::OAuth
My code is very simple:
oauth = Twitter::OAuth.new(consumer_token, consumer_secret)
oauth.authorize_from_access(access_token, access_secret)
client = Twitter::Base.new(oauth)
client.update("Updating my status from twitter gem. GREAT!")
Is there a problem with this particular gem ?
Thanks a lot for your help.
Luc
Have you created a .gems file and put twitter in it?
Depending on which heroku 'stack' you are on, you may need to do that instead of a bundler Gemfile. You can change your stack for one that uses bundler by doing this:
heroku stack:migrate bamboo-ree-1.8.7
Which makes bundler available (I think).
That is a common message that usually implies that you have a discrepancy between your local gems and the gems in heroku. If you are not using Bundler yet, you should. You will end un writing a very simple Gemfile that will tell Heroku (or any other entity using your code) which gems and versions you require.
http://gembundler.com/
I would suggest that you should use the heroku addon called 'apigee', ut makes twitter on heroku simple:
http://addons.heroku.com/apigee
I just got a sinatra app talking to Twitter through Heroku/Apigee, my rate limit went from 300 calls per hour to 20,000 calls per hour. Here's a step by step on what to do:
http://geeks.aretotally.in/mind/2011/1/8/increasing-api-limits-on-a-sinatra-twitter-app-with-twitter_.html
I am really a Java developer just playing around with Sinatra but let me know if I can help in anything.
Felipe

Resources