Be Careful that you don't Stub your Big Toe
59 comments Latest by Bin Wed, 01 Sep 2010 04:50:31 GMT
In a project that I’m currently working on, we’re handling recurring payments for subscribers. I’ve decided to play with a different payment service API on this project (TrustCommerce), which supposedly has one of the easier systems to handle recurring payments as well as one-time charges to the same credit cards. They store all the credit card data so that our delivered product to the client is CISP-compliant.
I came across the TrustCommerce Subscription plugin for Rails, which does just everything that I need to do in this first product release… as well as things that aren’t requirements just yet.
Well, I got my test account from TrustCommerce and was working on some RSpecs to test my new subscription and noticed that it was failing. After some snooping around the error responses, I realized that… test accounts don’t give you the ability to test the Citadel features of TrustCommerce. It’ll be another week or so before finish getting our account setup, so what am I to do? I really want to finish writing these specs and move on to the other portions that are dependent upon this working.
Suppose that you were going to perform something like this in an AR callback.
class BillingDetail < ActiveRecord::Base
# validations
before_create :store_credit_card_data_with_trust_commerce
private
def store_credit_card_data_with_trust_commerce
# some of this is still test data... prettyu much copied from the README
# TODO: refactor... but keep me out of controllers!
response = TrustCommerceGateway::Subscription.create(
:cc => self.credit_card_number,
:exp => '0412',
:name => self.customer_name,
:amount => 1,
:cycle => '1y',
:demo => 'y'
)
if response['status'] == 'approved'
self.billing_id = response['billingid']
else
# handle failure
end
end
end
Enter Mock Objects
Since I am unable to succesfully use the TrustCommerceGateway::Subscription.create method until I get our real account, I needed a simple way to emulate the interaction with the web service.
This can be done by using a Mock object, which RSpec provides for you.
TrustCommerceGateway::Subscription.stub!(:create).and_return( {expected response} )
Let’s look at the following spec file (much of it removed to protect the innocent).
module ValidBillingDetail
def valid_attributes
{ # a hash of valid key/values for this model }
end
def approved_trust_commerce_subscription
{ 'status' => 'approved', 'billingid' => '1093423' }
end
end
context "A new billing detail" do
include ValidBillingDetail
setup do
TrustCommerceGateway::Subscription.stub!(:create).and_return( approved_trust_commerce_subscription )
end
# bunch of other specs
specify "should store new billing info with 3rd party API and store the billingid" do
@billing_detail = BillingDetail.create( valid_attributes )
@billing_detail.billing_id.should_not_be nil
end
end
You’ll notice a few things. First, you’ll see that I’ve stubbed the create method and when it is called in the method in my model, it’ll return the hash that I’ve specified.
TrustCommerceGateway::Subscription.stub!(:create).and_return( approved_trust_commerce_subscription )
In the spec, you will see that I am checking that that the .billing_id.should_not_be nil. If you look back in the method in the model above, you will notice that an approved subscription returns a billing_id, which is set when the transaction is successful.
This is working out great for me and because the documentation is fairly easy to follow, I’m going to be able to mock much of the behavior that I’ll be using in the application, without needing to even connect to their API.
If you’re using RSpec, I highly encourage you to read more about mocks objects.
Enjoying the content? Be sure to subscribe to my RSS feed.






Hey Robby,
Very interesting. I’m mulling over subscription based ecommerce solutions for our app as well. Its been a bit sticky regarding a solid solution for recurring subscriptions.
Are you guys using something like ActiveMerchant with this project (I’ve heard it works well with TrustCommerce?) or are you using just the TrustCommerce subscription plugin?
From what I’ve seen it seems TrustCommerce is probably the best way to go in regards to Rails payment processing with recurring subscriptions. More than say PayPal Payment Pro. Would you agree?
Marston,
Based on my research on the available options that have a nice API for managing recurring payments… and I was impressed with their platform as a whole.
One of my requirements for an API was that I need to be able to make a charge against the credit card information that the 3rd party service is charging. In an effort to be CISP-compliant, they’ll host everything and I can make charges against the card based on my own recurring cycles.
As far as the library, I am currently just going to tuse the TrustCommerce plugin because of it’s focus on subscription type transactions, which is all that I’m working on in the application that I’m working on with my team.
Glad you find the subscription plugin useful. I have been very happy with TC in general. The API is intuitive and simple. As far as waiting for the Citadel features to be added, just ask. I have a test account enabled with full Citadel functionality.
Hi Robby,
Glad you found a solution that worked for you. Just thought I’d let you know that you can also just ask TrustCommerce to enable Citadel for your test account. That’s what I did. :)
Hey Robby,
I noticed in another blog post regarding the TC subscriptions plugin you had the following error:
{“status”=>”baddata”, “error”=>”merchantcantaccept”, “offenders”=>”action”}
You then posted a comment saying it was working. I’m getting the same errors in my test and was wondering what you did to solve the problem? (I’ve verified our account has Citadel enabled). Thanks if you can give any assistance.
Marston,
I am having a similar problem, tests run like a dream but… when I run my code I get
{“status”=>”baddata”, “error”=>”merchantcantaccept”, “offenders”=>”action”}
What was your fix? My environment.rb set up looks like this
TrustCommerceGateway::ACCOUNT_SETTINGS = { :custid => ‘123456’, :password => ‘password’, :vault_password => ‘password’ }
I don’t think this technique will work.
You stub the create! method, which I believe will cause your callbacks to not be executed.
Am I wrong here? I’m trying to do something similar. Test a “before_create” callback, but when I stub the model’s create! method, that callback never gets called.
Have you had this issue and if so, do you know of a workaround?
Useful information,thanks a lot.
ed hardy clothing
wholesale ed hardy
ed hardy boots
I am a Robby on Rails programmer. Enjoyed your post, it is fantastic…Thank you very much for sharing…...
hi i’m new to robby .. so this web site & Post is very useful for me .. thanks for sharing this information.. Tom
I am a Robby on Rails programmer. Enjoyed your post, it is fantastic…Thank you very much for sharing……
Prudential West
I am a Robby on Rails programmer. Enjoyed your post, it is fantastic…Thank you very much for sharing……
Wholesale Clothing
You then posted a comment saying it was working. I’m getting the same errors in my test and was wondering what you did to solve the problem? (I’ve verified our account has Citadel enabled). Thanks if you can give any assistance.
Wholesale Brand Name Clothing
You stub the create! method, which I believe will cause your callbacks to not be executed.
Wholesalers
t’ll be another week or so before finish getting our account setup, so what am I to do? I really want to finish writing these specs and move on to the other portions that are dependent upon this working.
Wow, now this is a project that a lot of people will be interested in. After all, subscriptions are making things so much easier for people to keep on getting the same thing without having to constantly worry about the actual buying all the time.
amateur cams
There are some very helpful people in this thread. Thanks guys. I am pretty new at Rails and admittedly, struggling. This post made me focus a lot more because of the code’s purpose.
writing jobs philippines
I am not particularly thrilled about stubbing my big toe so I went ahead and peruse your post. I am still working on the validation part. There are so many specifications that I have to consider in our business’s subscription code.
essay admissions
mbt shuguli
eryertyy
tyutyu
Always be acquainted of replica Chanel handbags , and analysis that the Chanel handbag has a attention card. The amount on the agenda is reproduced anxiously central the Chanel
I am a python guy. Very recently I had to use Robby on Rails for one of under graduate my projects and to be honest now I consider switching to Robby on Rails from python as it is the best choice of my context!!!
While the Louis vuitton bags is the one which makes you admirable wherever you go. This is not abandoned due to the architectonics of the aberant louis vuitton handbags . lv acquire got their own emphasis in our lives, for arcade or anywhere away afterwards acclimatized a louis vuitton with us.
Unlike added artist characterization hermes bags , simple claws on the birkin will accomplish you dribble at how able-bodied it enhances the all-embracing attending of a simple berkin bag .
While the Chanel changes hardly from year to year do not about buy chanel watches . All-embracing the Chanel bags has array of a aboveboard attending to it.
Unlike added artist characterization hermes bags , simple claws on the birkin will accomplish you dribble at how able-bodied it enhances the all-embracing attending of a simple berkin bag .
While the Chanel changes hardly from year to year do not about buy chanel watches . All-embracing the Chanel bags has array of a aboveboard attending to it.
So informative things are provided here,I really happy to read this post,I was just imagine about it and you provided me the correct information I really bookmark it,for further reading,So thanks for sharing the information.
The blow one wants can anon be called from the menu. Like the DV band format, there are Mini FASTLANE cameras evolving, which acquiesce one to accomplish basal alteration functions on the camera itself. Also one can just yield a afresh recorded Mini FASTLANE DVD and play it on about any FASTLANE DVD COLLECTION player. The Style: The Tiffany is one of those brands that actually mark the onset of a classic style and design on silver rings . Some of the designs of Tiffany earrings have become so common and popular, that they are bound to be copied by artisans all over. silver earrings are created either by using a mass production technique or by an individual jewelry designer who is striving to make a name for his services and capitalize on the original designs..
Demonstrate a unique new conceptjordan shoesAw01
niu niu
http://aionblogs.com/loseweightcapsules/ http://alchimagica.eu/lidadaidaihua2/ http://ami.im/lidadaidaihua2/ http://lidadaidaihua3.artistsblog.org/ http://blog.bbs-haarentor.de/wp-admin/edit.php
http://aionblogs.com/loseweightcapsules/ http://alchimagica.eu/lidadaidaihua2/ http://ami.im/lidadaidaihua2/ http://lidadaidaihua3.artistsblog.org/ http://blog.bbs-haarentor.de/wp-admin/edit.php
wow ,thanks !!!nice sharing
I think it’s fair to say our world economy has caught somewhat of a Virus. In true F&J style, here’s a brief description of the many forms of economic viruses affecting the markets…Tiffany Pendants and while you’re at it why don’t you make up your own virus in the comments section.We really should do more of these, while some of our jokes are meant for a more “adult”Tiffany Rings crowd (still safe for work and not vulgar or anything) – we’d like to post some jokes catered more towards are younger readers.Tiffany Cuff Links Specifically, short and simple jokes that kids can remember and tell their friends for a quick laugh.A commercial airplane is in flight to Chicago,Tiffany Bangles when a blonde woman sitting in economy gets up and moves to an open seat in the first class section. A flight attendant watches her do this, and politely informs the woman that she must return to her seat in the economy class because that’s the type of ticket she paid for.
captured by the Nazis WASHINGTON — Enlisted by members of the House and Senate, presidential aide Rebecca Tandy brought a
copy of the international climate-change treaty to President Bush’s Monday and asked him to sign a birthday document for a
Paloma PicassodeskJapanese dignitary named
“Kyoto Protocol.”A man appears before St. Peter at the pearly gates. “Have you ever done anything of particular merit?” St.
Peter asks. There is a new virus. The code Return to Tiffanyname is “WORK.” If you
receive WORK from your colleagues, your boss, via e-mail, or from anyone else-do not touch WORK under any circumstances. This
virus wipes out yourTiffany 1837 private life
completely.During WW II a British fighter Tiffany keys pilot was shot down over Germany
captured by the Nazis. ,Tiffany Notes so the
German doctor amputated his left arm. He requested that they drop his arm over his base in England. So the Germans did.A
Missouri pickup, Tiffany Somersetdrove
several miles to a neighboring farm and knocked on the farmhouse door. A young boy about 12 opened the door.An elderly man
was at home, dying in bed. He smelled the aroma of his favourite chocolate chip cookies baking. He wanted one last cookie
before he died…
Q: How many lawyers does it take to change a light bulb? This is a question that’s been at the forefront of discussion amongst the most prestigious scholars and lawmakers of the world. Finally, after getting them all together – the question has been answered.replica Gucci Watches A: Such number as may be deemed necessary to perform the stated task in a timely and efficient manner within the strictures of the following agreement. http://www.silvertiffany.com/7-tiffany-rings">Tiffany Rings Whereas the party of the first part, also known as ‘the lawyers’ and the party of the second part, also known as ‘the light bulb’ do hereby agree to a transaction wherein the party of the second part shall be removed from the current position as a result of failure to perform previously agreed upon duties, i.e. the lighting, elucidation, and otherwise illumination of the area ranging from the front (North) door, through the entryway, terminating at an area just through the primary living area,http://www.silvertiffany.com/5-tiffany-bangles">Tiffany Bangles demarcated by the beginning of the carpet, any spillover illumination being at the option of the party of the second part and not required by the aforementioned agreement between the parties. The aforementioned removal transaction shall include, but not be limited to, the following steps
Q: How many lawyers does it take to change a light bulb? This is a question that’s been at the forefront of discussion amongst the most prestigious scholars and lawmakers of the world. Finally, after getting them all together – the question has been answered.replica Gucci Watches A: Such number as may be deemed necessary to perform the stated task in a timely and efficient manner within the strictures of the following agreement. Tiffany Rings Whereas the party of the first part, also known as ‘the lawyers’ and the party of the second part, also known as ‘the light bulb’ do hereby agree to a transaction wherein the party of the second part shall be removed from the current position as a result of failure to perform previously agreed upon duties, i.e. the lighting, elucidation, and otherwise illumination of the area ranging from the front (North) door, through the entryway, terminating at an area just through the primary living area,Tiffany Bangles demarcated by the beginning of the carpet, any spillover illumination being at the option of the party of the second part and not required by the aforementioned agreement between the parties. The aforementioned removal transaction shall include, but not be limited to, the following steps
The aforementioned removal transaction shall include, but not be limited to, the following steps:Tiffany Pendants light-bulb1. The party of the first part shall, with or without elevation at his option, by means of a chair, step stool, ladder or any other means of elevation, Tiffany Somerset grasp the party of the second part and rotate the party of the second part in a counter clockwise direction, said direction being non-negotiable. Tiffany Accessories Said grasping and rotation of the party of the second part shall be undertaken by the party of the first part to maintain the structural integrity of the party of the second part, notwithstanding the aforementioned failure of the party of the second part to perform the customary and agreed upon duties.
both parties stipulate that structural failure of the party of the second part may be incidental to the aforementioned failure to perform and in such case the party of the first part shall Tiffany 1837 be held blameless for such structural failure insofar as the non-negotiable directional codicil is observed by the party of the first part throughout. 2. Upon reaching a point where the party of the second part becomes seperated from the party of the third part, also known as the ‘receptacle’, Return to Tiffany the party of the first part shall have the option of disposing of the party of the second part in a manner consistent with all applicable state, local, and federal statutes.
I would like to see, that write / read are done on master, only asynchronous reads are done from slave. London Busty Escorts
You can have a look at it. coats & jackets jordan shoes The quality is so good. abercrombie and fitch abercrombie & fitch Abercrombie and fitch outle
Christian Louboutin shoes Christian Louboutin boots coach outlet coach handbag coach totes diesel jeans True Religion Jeans levis jeans spyder jacket ski pants spyder ski wear bape shoes bape jackets ED Hardy Discount ED Hardy ED Hardy Outlet
Monogram Dentelle Louis Vuitton Speedy 30 Golden M95397 Louis Vuitton Speedy 30 Golden Louis Vuitton Speedy 30 Silver M95398 Louis Vuitton Speedy 30 Silver Louis Vuitton Batignolles Horizontal M95399 Louis Vuitton Batignolles Horizontal Louis Vuitton Batignolles Horizontal Silver M95400 Louis Vuitton Batignolles Horizontal Silver
Monogram Macassar Louis Vuitton Davis M56708 Louis Vuitton Davis Louis Vuitton Bass MM M56715 Louis Vuitton Bass Louis Vuitton Bass PM M56717 Louis Vuitton Bass Louis Vuitton Porte Documents Voyage PM M40225 Louis Vuitton Porte Documents Voyage Louis Vuitton Porte Documents Voyage GM M40224 Louis Vuitton Porte Documents Voyage Louis Vuitton Pochette Document M56721 Louis Vuitton Pochette Document Louis Vuitton Soft Briefcase M56719 Louis Vuitton Soft Briefcase
In the spec, you will see that I am checking that that the .billing_id.should_not_be nil. If you look back in the method in the model above, you will notice that an approved subscription returns a billing_id, which is set when the transaction is successful.
ers, http://www.pradabag.org/prada-leather-handbag/prada-leather-handbag-51-b0.html>prada leather handbags the t
I think blogs are small websites that are used to introduce the knowledge of those people that are really intelligent but can not afford a website
I’m working on a few blog articles that I’ll be posting over the next few weeks. The other day, I got another email from someone that asked me if I would write about something that I mentioned briefly in a blog post. This got me thinking… perhaps there are things that you’d like me write something on? In general, I try to keep a broad range of topics that relate to Ruby/Rails circulating and I’m planning a major overhaul to my blog (switch to mephisto in the near future?) and working on more tutorials, especially as we near the release of my book as a O’Reilly Rough Cut… and when it finally makes it to print. :-)
we’re handling recurring payments for subscribers. I’ve decided to play with a d
Nike Air Jordan Flight 7.5,Nike Air Jordan Flight 7.5
air nike air force one,air nike air force one
air force high,air force high
air force 1 mid,air force 1 mid
Nike Air Jordan 3.5,Nike Air Jordan 3.5
Nike Air Jordan Fusion 8,Nike Air Jordan Fusion 8
Air Jordan 24,Air Jordan 24
http://www.christianlouboutinbay.com/christian-louboutin-boots-c-239.html Christian Louboutin Boots http://www.christianlouboutinbay.com/ Christian Louboutin Sale http://www.christianlouboutinbay.com/ Christian Louboutin On Sale www.christianlouboutinbay.com Christian Louboutin 2010
Thanks for posting this. Marion Barber Jerseys Very nice recap of some of the key points in my talk. I hope you and your readers find it useful! Thanks again http://www.nflcowboysjerseys.com/cowboys-jerseys-c-1.html Cowboys Jersey
ghd hair ghd australia ghd straighteners pink hair straightenrs hot hair ghd mk4 hair irons ghd hair styler ceramic straighteners straightener hair hair straightening irons straightening irons straightners ghd iv styler mini hair straightener best ghd straighteners hair straighener sale hair straightener ghd pink styler
Ladies are crazy about Christian Louboutin shoes. If you want keep the same pace with the trend. Christian Louboutin could be your best choice. http://christianlouboutinnyc.com/
If you love shoes, and I´m sure you do, then you may have thought about getting some new shoes that are really stylish, modern and cool looking. Well, if that´s the case then you should waste no more time walking through your neighborhood because here you will find everything you are looking for. Just listen to my advice and take a few minutes of your life and pay a visit to Alexandermcqueenoutlet Here at this great site you will find everything you seek. http://alexandermcqueenoutlet.com/
Cartier for sale oris watches replica Concord Panerai watches replica Hermes Blancpain watches replica Louis Vuitton ebel replica oris for sale Christian Dior for sale Concord watches Glashutte for sale Rado for sale Jaquet droz for sale Bvlgari replica DeWitt replica chopard for sale
It’s good to see this information in your post, i was looking the same but there was not any proper resource, thanx now i have the link which i was looking for my research. . . . . . xiaoxiao123 08 30 Juicy Couture Omega Watches +Men.html”>breitling navitimer heritage
Gucci Small Agenda 115240 A0V1G 2019 Gucci Small Agenda 115240 A0V1G 9022 Gucci Standard Agenda 115241 A0V1G 1000 Gucci Standard Agenda 115241 A0V1G 2019 Gucci Standard Agenda 115241 A0V1G 9022 Gucci Belt Bag 233269 FCIGX 8588 Gucci Belt Bag 28566R F40JR 1000 Gucci Belt Bag 28566R F40JR 8588 Gucci Belt Bag 28566R F4FOR 9791 Gucci Briefcase 201480 BEG1G 1000 Gucci Briefcase 201480 BEG1G 2145 Gucci Briefcase 201480 FCIEG 9643 Gucci Briefcase 201480 FP47N 4075 Gucci Briefcase 223652 FCIEN 9643 Gucci Briefcase 231838 FAG9N 4092 Gucci Briefcase 231850 A7M0N 2140 Gucci Briefcase 231850 A7M0Z 1107 Gucci Briefcase 231850 FP43N 9080 Gucci Briefcase 232603 A7M0N 2140 Gucci Briefcase 246408 FWCZG 9791 Gucci Men’s Briefcase 201851 FCIWX 8588 Gucci Men’s Briefcase 201851 FJG5X 1000 Gucci Men’s Briefcase 34044R A0V1R 2019 Gucci Portfolio 232601 A7M0N 2140 Gucci Medium Computer Case 194297 FCIVX 9643 Gucci Medium Computer Case 201750 BEG1G 2145 Gucci Cosmetic Case 224093 FFKPG 9791 Gucci Cosmetic Case 145750 F4DYG 9643 Gucci Cosmetic Case 145750 F4DYG 9773 Gucci Cosmetic Case 153228 AA61G 5709 Gucci Cosmetic Case 153228 AA61G 9022 Gucci Cosmetic Case 153228 FN92G 9752 Gucci Cosmetic Case 212122 FFPAG 9761 Gucci Cosmetic Case 224093 FFKPG 9765 Gucci Cosmetic Case 245959 FJ72R 1000 Gucci Large Cosmetic Case 224089 FJ72R 1000 Gucci Large Cosmetic Case 224091 FJ72R 4506 Gucci Large Cosmetic Case 29595R F40IR 9643 Gucci Medium Cosmetic Case 224090 FJ72R 1000 Gucci Medium Cosmetic Case 224090 FJ72R 4506 Gucci Small Cosmetic Case 29596R F40IR 9643 Gucci Carry-on Duffel 201479 FCIZG 8501