Skip to content
Browse files

added tests for new methods

  • Loading branch information...
1 parent be394f5 commit 90b8827017c4bc55caf77b6d77b3581982f94e64 @mateuszzawisza mateuszzawisza committed with duff Mar 4, 2010
Showing with 18 additions and 1 deletion.
  1. +1 −0 lib/spreedly/mock.rb
  2. +17 −1 test/spreedly_gem_test.rb
View
1 lib/spreedly/mock.rb
@@ -147,6 +147,7 @@ def subscribe(plan_id)
def add_fee(args)
raise "Unprocessable Entity" unless (args.keys & [:amount, :group, :name]).size == 3
+ raise "Unprocessable Entity" unless active?
nil
end
end
View
18 test/spreedly_gem_test.rb
@@ -77,7 +77,7 @@ def self.only_real
end
should "expose and parse attributes" do
- subscriber = create_subscriber
+ subscriber = create_subscriber('bob')
assert_kind_of Time, subscriber.created_at
assert !subscriber.active
assert !subscriber.recurring
@@ -261,13 +261,29 @@ def self.only_real
end
context "adding fees" do
+
+ setup do
+ @regular_plan = Spreedly::SubscriptionPlan.all.detect{|e| e.name == "Test Regular Plan"}
+ assert @regular_plan, "For this test to pass in REAL mode you must have a regular plan in your Spreedly test site with the name \"Test Regular Plan\"."
+ end
+
should "be able to add fee to user" do
sub = create_subscriber
+ sub.subscribe(@regular_plan.id)
sub.add_fee(:name => "Daily Bandwidth Charge", :amount => "2.34", :description => "313 MB used", :group => "Traffic Fees")
end
+ should "throw an error when add fee to not active user" do
+ sub = create_subscriber
+ ex = assert_raise(RuntimeError) do
+ sub.add_fee(:name => "Daily Bandwidth Charge", :amount => "2.34", :description => "313 MB used", :group => "Traffic Fees")
+ end
+ assert_match %r{Unprocessable Entity}, ex.message
+ end
+
should "throw an error when add fee with incomplete arguments" do
sub = create_subscriber
+ sub.subscribe(@regular_plan.id)
ex = assert_raise(RuntimeError) do
sub.add_fee(:name => "Daily Bandwidth Charge", :description => "313 MB used", :group => "Traffic Fees")
end

0 comments on commit 90b8827

Please sign in to comment.
Something went wrong with that request. Please try again.