I'm using nginx locally so I can use ssl, *.myapp.com is going to 127.0.0.1:3000, I've set Capybara server_port to on 3000 and Capybara.app_host = "subdomain.myapp.com". Is that what's messing things up?
To add to what Ryan said...it depends on what you mean. If you want to use VCR to record/replay HTTP requests made by your rack application, and you are using capybara + selenium to do full-stack integration testing--then yes. VCR isn't coupled to a particular capybara driver (or any testing library, really) so it should work fine, as long as you are making HTTP requests with one of the supported HTTP client libraries.
If you are wanting to use capybara + selenium to test-drive an external website like what Ryan demonstrated with capybara-mechanize...then I'm not sure. I wasn't aware capybara-mechanize allowed you to do that.
Basically, VCR will work with anything as long as you are using one of the supported HTTP client libraries (or a library built on top of one of those--like how rest-client is built on top of Net::HTTP), you have control of the ruby process where the HTTP requests are being made, and you have a way to wrap the code making the HTTP requests in a VCR.use_cassette call.
While on SOAP and webservice, the rails app that I work on is expected to expose couple of methods as SOAP Webservice. I know Ruby has ditched SOAP in favor of REST, but I really dont have an option as the client app expect it. Is there any gems out there that support creation of a SOAP web service on Rails 3.x?
Thanks!
1) The save_with_subscription method is doing a valid? check and therefore does not raise an exception when validation fails. I am doing save! inside the valid? check because if the data somehow got invalid between then and now I want to know about it.
2) Handling cases where save fails is tricky because the transaction has already been placed. I suppose you could do an automatic void but then there's always the possibility of that not going through. I think this is better to be handled manually. If save fails then it will raise an exception and hopefully there is something setup to notify you when an exception occurs so you can handle the situation manually (such as voiding the transaction).
I wish there was a good solution for this but I can't think of any alternative recurring payment method that will work in Germany. If you have suggestions please let me know.
I have not yet made the Pro features open source, but i plan to at some point. I just want to make sure it's air tight before I do because I'm dealing with more sensitive information.
To do this you can place any sensitive data config files in the shared directory on the server and then symlink/copy them over upon each Capistrano deploy. See the how I'm doing it here for an example.
This is using the new hash syntax present in Ruby 1.9.2. If you are using Ruby 1.8.7 you would need to convert this to the old hash syntaxrender :nothing => true.
Glad you like the revised episodes. The 3.1 tag is for episodes where the main topic is a feature of 3.1 and cannot be applied to 3.0. It is true one would need to translate the CoffeeScript into JavaScript, but other than this the functionality is the same.
Pagination is tricky because I'm not certain how you would sort across pages. You may want to do simple up/down arrow buttons that increment/decrement the position instead of drag + drop sorting.
I don't think so, but I haven't tried it. VCR needs to stub out the HTTP request, so that needs to happen in Ruby. I don't think the Capybara Selenium driver uses Ruby at all to perform the HTTP requests. It instead communicates with Selenium at a higher level. I believe the same goes for Capybara Webkit and other alternatives.
That said, what you can do is setup a proxy Rack server which all remote requests go through. This can forward all HTTP requests to their remote destination using Net::HTTP and therefore use VCR to record it. It would look like this: Capybara > Selenium > Rack proxy server > Remote server.
Since VCR only stubs HTTP requests it won't work over an SSH tunnel. However what you can do is setup a proxy server that is before the SSH tunnel and have VCR record requests that go to that server. I haven't actually tried this, and it's a bit advanced, but hopefully it will give you some ideas.
The delivery_method isn't a method that you define. It is normally set to :smtp or :sendmail depending on what you want to use to send email. See the guide for further details.
airbrake also has a (experimental) javascript exception notifier, that logs javascript exceptions too. the stack trace is often not too useful, but it's worth a look if your application relies heavily on javascript.
the free plan is good enough to test it out and setup is easy
what bugs me a little bit about it is, that I can't log ruby and javascript exceptions to different projects, maybe in the future if I have a little time I can make a fork of the gem that will do just that
It's worth to mention that now this is the default behaviour, as Rails offers query cache, so you don't have to store the result of an expensive query on an instance variable. If your application performs the same query on the same request more than once, Rails automatically returns the result of the first execution, without touching the database twice for the same query.
Additionaly, if you enable identity map, you have the extra benefit of always getting the same object representing a record of your database, instead of creating new objects.
You're sure, but to sort by id or created_at retrieves the same record on this case. And it's better to sort by an integer column than by a date column, for performance reasons.
First: thanks so much for this cast, it was great and really informative!
Second: say I want to group my orders by week instead of per day. I am not very savvy with how this works in a helper method, could you give an example?
Btw, take a look on em-net-http (https://github.com/jfairbairn/em-net-http). Sometimes SOAP server might respond slowly. I used this library with Savon to improve performance and I reached it.
I went through this tutorial on a new app with Rails 3.1.1 and it worked perfectly. However, I am now trying to use this on an existing app using Rails 3.0.9 with ActionMailer and DEVISE, and it does not work. I am pretty confident DEVISE uses ActionMailer based on the settings, but whenever I send an email to another use, they get the email and not me.
Has anyone been able to get this to work with DEVISE?
I haven't been able to use VCR in tests with :js => true (capybara + selenium)
The first time I run the test it passes and the cassette is recorded.
However, when I use the cassette, the test fails with Unregistered request:
POST http://127.0.0.1:7055/hub/session/..... with body '{"url":"http://subdomain.myapp.com/settings"}'
The url is different every time.
I'm using nginx locally so I can use ssl, *.myapp.com is going to 127.0.0.1:3000, I've set Capybara server_port to on 3000 and Capybara.app_host = "subdomain.myapp.com". Is that what's messing things up?
We used this to communicate with Yodlee API. Worked wonderfully!
Can you give any example, how to use em-net-http with Savon?
Regards
To add to what Ryan said...it depends on what you mean. If you want to use VCR to record/replay HTTP requests made by your rack application, and you are using capybara + selenium to do full-stack integration testing--then yes. VCR isn't coupled to a particular capybara driver (or any testing library, really) so it should work fine, as long as you are making HTTP requests with one of the supported HTTP client libraries.
If you are wanting to use capybara + selenium to test-drive an external website like what Ryan demonstrated with capybara-mechanize...then I'm not sure. I wasn't aware capybara-mechanize allowed you to do that.
Basically, VCR will work with anything as long as you are using one of the supported HTTP client libraries (or a library built on top of one of those--like how rest-client is built on top of Net::HTTP), you have control of the ruby process where the HTTP requests are being made, and you have a way to wrap the code making the HTTP requests in a
VCR.use_cassette
call.Very!, Very! Nice =)
Instead of letter_opener you can also use http://mocksmtpapp.com/ it's simply brilliant to test emails in development.
While on SOAP and webservice, the rails app that I work on is expected to expose couple of methods as SOAP Webservice. I know Ruby has ditched SOAP in favor of REST, but I really dont have an option as the client app expect it. Is there any gems out there that support creation of a SOAP web service on Rails 3.x?
Thanks!
but the appointment will be of class Appointment not AppointmentDecorator, or?
Thanks for this, it also works perfect in Rails 3.1
Thanks Ryan!
The previous code works for new models, but you can get the existing id like this:
Heh. I'm glad you still have the source on github for pro. That
hande_none
was driving me bonkers...+1 on handling insufficiant funds, etc
Hi,
I am using cancan 1.6.7 on a Rails 2.2.3 app.
My ability class is as follows:
When loading a page, I am getting the following error:
NameError in AController#edit
uninitialized constant CanCan::Ability::I18n
Any one knows why?
Thanks.
Good questions.
1) The
save_with_subscription
method is doing avalid?
check and therefore does not raise an exception when validation fails. I am doingsave!
inside thevalid?
check because if the data somehow got invalid between then and now I want to know about it.2) Handling cases where save fails is tricky because the transaction has already been placed. I suppose you could do an automatic void but then there's always the possibility of that not going through. I think this is better to be handled manually. If
save
fails then it will raise an exception and hopefully there is something setup to notify you when an exception occurs so you can handle the situation manually (such as voiding the transaction).Thanks for posting this, I had forgotten about the
prop
method.I wish there was a good solution for this but I can't think of any alternative recurring payment method that will work in Germany. If you have suggestions please let me know.
Yes, I will be adding a PayPal checkout option soon, stay tuned.
I will be adding a PayPal checkout option soon, stay tuned.
I have not yet made the Pro features open source, but i plan to at some point. I just want to make sure it's air tight before I do because I'm dealing with more sensitive information.
PayPal support will be coming soon. Thanks for your interest in RailsCasts Pro.
To do this you can place any sensitive data config files in the shared directory on the server and then symlink/copy them over upon each Capistrano deploy. See the how I'm doing it here for an example.
I don't plan to switch to Stripe since I already have Braintree setup. They're both great though.
I'm using Braintree at the moment, but will be adding PayPal as an alternative checkout option soon.
This is using the new hash syntax present in Ruby 1.9.2. If you are using Ruby 1.8.7 you would need to convert this to the old hash syntax
render :nothing => true
.Sounds like a fun idea for a future episode, thanks for the suggestion.
Glad you like the revised episodes. The 3.1 tag is for episodes where the main topic is a feature of 3.1 and cannot be applied to 3.0. It is true one would need to translate the CoffeeScript into JavaScript, but other than this the functionality is the same.
Pagination is tricky because I'm not certain how you would sort across pages. You may want to do simple up/down arrow buttons that increment/decrement the position instead of drag + drop sorting.
Thanks for the suggestion. Pushing API requests into a background process is a good thing and would make a good episode. Good idea.
Thanks for the suggestion. I plan to cover TTD more in future pro episodes.
I don't think so, but I haven't tried it. VCR needs to stub out the HTTP request, so that needs to happen in Ruby. I don't think the Capybara Selenium driver uses Ruby at all to perform the HTTP requests. It instead communicates with Selenium at a higher level. I believe the same goes for Capybara Webkit and other alternatives.
That said, what you can do is setup a proxy Rack server which all remote requests go through. This can forward all HTTP requests to their remote destination using Net::HTTP and therefore use VCR to record it. It would look like this: Capybara > Selenium > Rack proxy server > Remote server.
Since VCR only stubs HTTP requests it won't work over an SSH tunnel. However what you can do is setup a proxy server that is before the SSH tunnel and have VCR record requests that go to that server. I haven't actually tried this, and it's a bit advanced, but hopefully it will give you some ideas.
The
delivery_method
isn't a method that you define. It is normally set to:smtp
or:sendmail
depending on what you want to use to send email. See the guide for further details.Coda, I found this link:
http://railsforum.com/viewtopic.php?id=40499
so your >> here? <<
could be something like
not sure about the content tag and how you specify the class/id for CSS.
I'm using a fieldset as follows:
Good luck :)
airbrake also has a (experimental) javascript exception notifier, that logs javascript exceptions too. the stack trace is often not too useful, but it's worth a look if your application relies heavily on javascript.
the free plan is good enough to test it out and setup is easy
what bugs me a little bit about it is, that I can't log ruby and javascript exceptions to different projects, maybe in the future if I have a little time I can make a fork of the gem that will do just that
Thanks Jakub, i was stuck and you came through for me.
When you set the action mailer delivery method in your production config file, where should that method live?
thank you! could you make a PRO screencast with basics of TTD?
It's worth to mention that now this is the default behaviour, as Rails offers query cache, so you don't have to store the result of an expensive query on an instance variable. If your application performs the same query on the same request more than once, Rails automatically returns the result of the first execution, without touching the database twice for the same query.
Additionaly, if you enable identity map, you have the extra benefit of always getting the same object representing a record of your database, instead of creating new objects.
You're sure, but to sort by id or created_at retrieves the same record on this case. And it's better to sort by an integer column than by a date column, for performance reasons.
Definitely. Or just "scope" as it is now.
Man, this is just begging to be revised! :)
Hi ryan,
First: thanks so much for this cast, it was great and really informative!
Second: say I want to group my orders by week instead of per day. I am not very savvy with how this works in a helper method, could you give an example?
I used it in our project. Cool library!!!
Btw, take a look on em-net-http (https://github.com/jfairbairn/em-net-http). Sometimes SOAP server might respond slowly. I used this library with Savon to improve performance and I reached it.
I wanted only Users with the admin attribute set to true to access resque-web.
Since we're using Devise, the current user is accessible like this:
request.env['warden'].user
So I made the below off the back of the example here:
http://www.scottw.com/securing-resque-server-rails-3
If we were using Devise's "roles" (where each role has it's own table) we could simply do this in the routes file:
I went through this tutorial on a new app with Rails 3.1.1 and it worked perfectly. However, I am now trying to use this on an existing app using Rails 3.0.9 with ActionMailer and DEVISE, and it does not work. I am pretty confident DEVISE uses ActionMailer based on the settings, but whenever I send an email to another use, they get the email and not me.
Has anyone been able to get this to work with DEVISE?
Hi guys!
I'm having a little problem trying to understand 'content_tag_for', could you please give me a hint?
I'm not pretty sure how to get/use the IDs from inside a partial :( here is my code:
Thanks in advance! :D
I think you have to eagerload all associations needed by your view in you controller:
Then there should be no extra query when calling user_decorator.appointment.
Hi,
There is a mistake in the asciicast here:
Text encoding trouble probably :)
I've been doing:
I like your way better, although I wish this was possible: