Skip to content

Instantly share code, notes, and snippets.

@jacknoble
Created January 21, 2016 21:05
Show Gist options
  • Save jacknoble/8d33dd1c4d2b39af0522 to your computer and use it in GitHub Desktop.
Save jacknoble/8d33dd1c4d2b39af0522 to your computer and use it in GitHub Desktop.
require "spec_helper"
require "signup"
describe Signup do
describe "#save" do
it "creates an account with one user" do
signup = Signup.new(email: "[email protected]", account_name: "Example")
allow(Account).to receive(:create!).and_return(Account.new)
allow(User).to receive(:create!).and_return(User.new)
expect(signup.save).to be(true)
end
end
describe "#user" do
it "returns the user created by #save" do
email = "[email protected]"
account_name = "Example"
signup = Signup.new(email: email, account_name: account_name)
account = Account.new(name: account_name)
allow(Account).to receive(:create!).and_return(account)
allow(User).to receive(:create!).and_return(User.new(account: account, email: email))
signup.save
result = signup.user
expect(result.email).to eq("[email protected]")
expect(result.account.name).to eq("Example")
expect(Account).to have_received(:create!).with(name: account_name)
expect(User).to have_received(:create!).with(account: account, email: email)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment