Sha256: 1c099733e41add5945da164f6aec944457b224817c370360d104f79665b74194

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe CanceledAccount do
  subject { CanceledAccount.create() }

  it { should belong_to(:plan) }

  it "doesn't populate anything" do
    subject.name.should be_nil
    subject.keyword.should be_nil
  end
end

describe CanceledAccount, "given an account" do
  let(:account) { Factory(:account, :billing_email => "billing@example.com") }
  let(:mail)    { stub('cancelation_notification', :deliver => true) }

  before do
    BillingMailer.stubs(:cancelation_notification => mail)
    Factory(:membership, :account => account)
  end

  subject { CanceledAccount.create(:account => account) }

  it "populates its name and keyword from the given account" do
    subject.name.should == account.name
    subject.keyword.should == account.keyword
  end

  it "populates the billing_email from the customer's email from the given account" do
    subject.billing_email.should_not be_nil
    subject.billing_email.should == account.customer.email
  end

  it "saves the memberships and users as json from the given account" do
    memberships_json = account.memberships.to_json(:include => { :user => { :only => [:email, :name, :created_at]}}, :only => [:admin, :created_at])
    subject.memberships.should == memberships_json
    JSON.parse(subject.memberships).should be
  end

  it "populates the plan from the given account" do
    subject.plan_id.should == account.plan_id
    subject.plan.should == account.plan
  end

  it "populates the started_at from the given account's creation date" do
    subject.started_at.should == account.created_at
  end

  it "sends a notification email" do
    BillingMailer.should have_received(:cancelation_notification).with(subject)
    mail.should have_received(:deliver)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saucy-0.16.1 spec/models/canceled_account_spec.rb
saucy-0.16.0 spec/models/canceled_account_spec.rb