Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:30:04+00:00 2026-06-18T12:30:04+00:00

I have the following: let(:coupon) { mock_model Coupon, code: ‘special’ } let(:cart) { mock_model

  • 0

I have the following:

let(:coupon) { mock_model Coupon, code: 'special' }
let(:cart) { mock_model Cart }

it "assigns a coupon to the cart" do
  post :redeem_coupon, coupon: {coupon: coupon.code}
  assigns(:cart).coupon.should eql(coupon)
end

I have the following error with that:

 Failure/Error: assigns(:cart).coupon.should eql(coupon)
 NoMethodError:
   undefined method `coupon' for nil:NilClass

I just want to make sure the following works:

@cart = current_cart

if request.post?
  coupon = Coupon.find_active_by_code(params[:coupon][:coupon], @cart.subtotal, current_member)
  if coupon
    @cart.coupon = coupon
    @cart.save!
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:30:06+00:00Added an answer on June 18, 2026 at 12:30 pm

    I would guess current_cart is returning nil. You can stub it with the mock cart that you already created:

    before { subject.stub(:current_cart) { cart } }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: %let host = HostThatSendsEmail; %let todayDate = &SYSDATE9; signon
Let's say we have following code: struct A{ virtual ~A(){} void f(){ p =
Let's say I have the following code: class MyClass(object): def __init__(self, param): self.param =
Assume I have the following code: let a = ref 4. printfn 1) a
I have the following sample code let x = [return 1::IO(Int), return 2::IO(Int)] So
I have the following code: #light let rec fib n = if n=0 ||
I have the following f# code: let mutable argNum = 0 let cmdArgs =
I have the following question: Let's assume the code below: ... <h:form id=..> <table>
Let's say I have following code: int f() { int foo = 0; int
Let's say I have following code: List<string> numbers = new List<string> { 1, 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.