rspec

How do I mock a response of a controller that redirects to an external API?

只愿长相守 提交于 2020-03-03 04:51:37
问题 My orders_controller needs to forward an order to a payment gateway. It's making my tests fail: No route matches [GET] "/v2/checkout/payment.html" That's is the URL that the PaymentGateway object redirects to. How can I trick my tests into thinking that the payment gateway returned a response? In reality, it doesn't. It may or may not return the user depending on his choice. It's similar to paying with Paypal. def create @order = current_user.orders.build(params[:order]) @order.add_line_items

How do I mock a response of a controller that redirects to an external API?

為{幸葍}努か 提交于 2020-03-03 04:51:27
问题 My orders_controller needs to forward an order to a payment gateway. It's making my tests fail: No route matches [GET] "/v2/checkout/payment.html" That's is the URL that the PaymentGateway object redirects to. How can I trick my tests into thinking that the payment gateway returned a response? In reality, it doesn't. It may or may not return the user depending on his choice. It's similar to paying with Paypal. def create @order = current_user.orders.build(params[:order]) @order.add_line_items

How do I mock a response of a controller that redirects to an external API?

孤街醉人 提交于 2020-03-03 04:48:06
问题 My orders_controller needs to forward an order to a payment gateway. It's making my tests fail: No route matches [GET] "/v2/checkout/payment.html" That's is the URL that the PaymentGateway object redirects to. How can I trick my tests into thinking that the payment gateway returned a response? In reality, it doesn't. It may or may not return the user depending on his choice. It's similar to paying with Paypal. def create @order = current_user.orders.build(params[:order]) @order.add_line_items

Rails fragment cache testing with RSpec

浪尽此生 提交于 2020-02-26 07:21:26
问题 I feel like this is a not-so-much documented topic, at least I've had a lot of trouble finding our about the best practices here. I'm fragment caching in the view using a cache_key: %tbody - @employees.each do |employee| - cache employee do %tr[employee] %td= employee.name %td= employee.current_positions %td= employee.home_base %td= employee.job_classes Now I can add :touch => true on the :belongs_to side of my has_many associations and this will do everything I need to keep this fragment

Rails fragment cache testing with RSpec

强颜欢笑 提交于 2020-02-26 07:21:04
问题 I feel like this is a not-so-much documented topic, at least I've had a lot of trouble finding our about the best practices here. I'm fragment caching in the view using a cache_key: %tbody - @employees.each do |employee| - cache employee do %tr[employee] %td= employee.name %td= employee.current_positions %td= employee.home_base %td= employee.job_classes Now I can add :touch => true on the :belongs_to side of my has_many associations and this will do everything I need to keep this fragment

RSpec: What is the difference between let and a before block?

那年仲夏 提交于 2020-02-26 04:37:06
问题 What is difference between let and a before block in RSpec? And when to use each? What will be good approach (let or before) in below example? let(:user) { User.make !} let(:account) {user.account.make!} before(:each) do @user = User.make! @account = @user.account.make! end I studied this stackoverflow post But is it good to define let for association stuff like above? 回答1: People seem to have explained some of the basic ways in which they differ, but left out before(:all) and don't explain

Testing that Devise is re-sending confirmation instructions email in a background worker

核能气质少年 提交于 2020-02-25 01:30:02
问题 I want to send Devise confirmation instructions to users a second time if they haven't confirmed within two days of signing up, however I can't seem to get my success case test to pass. Background worker (runs once a day): class ResendConfirmationWorker include Sidekiq::Worker sidekiq_options queue: :resend_confirmation, retry: false def perform d = Time.zone.now - 2.days users = User.where.not(confirmation_sent_at: nil) .where(confirmed_at: nil) .where(created_at: d.beginning_of_day..d.end

Testing that Devise is re-sending confirmation instructions email in a background worker

房东的猫 提交于 2020-02-25 01:28:27
问题 I want to send Devise confirmation instructions to users a second time if they haven't confirmed within two days of signing up, however I can't seem to get my success case test to pass. Background worker (runs once a day): class ResendConfirmationWorker include Sidekiq::Worker sidekiq_options queue: :resend_confirmation, retry: false def perform d = Time.zone.now - 2.days users = User.where.not(confirmation_sent_at: nil) .where(confirmed_at: nil) .where(created_at: d.beginning_of_day..d.end

create a post request using poltergeist and capybara

杀马特。学长 韩版系。学妹 提交于 2020-02-24 12:01:32
问题 I'm transitioning from Capybara backed by the default Rack driver to Capybara backed by Poltergeist. For frustrating reasons, I need to manipulate session data before loading a page. But I couldn't figure out how to manipulate the session directly with the Rack driver, so I Capybara.current_session.driver.submit :post, "/current_search", {:session => :data } Unfortunately, the Poltergeist driver object has no submit method, as the Rack driver had. There are three possibilities: How do I

RSpec - Undefined method `key?'

戏子无情 提交于 2020-02-23 07:18:18
问题 I'm trying to run a test for rendering templates and ran into the error: undefined method `key?' for 1014:Fixnum The stub of my model's instance works as it should in my route tests but not so much here. What am I doing wrong? describe RestaurantsController do let(:restaurant) { FactoryGirl.build_stubbed(:restaurant) } describe 'GET #show' do before { get :show, restaurant.id } it { should render_template('show') } end end Full Error 1) RestaurantsController GET #show Failure/Error: before {