Skip to content

Instantly share code, notes, and snippets.

@radar
Last active December 11, 2015 02:59
Show Gist options
  • Save radar/4534694 to your computer and use it in GitHub Desktop.
Save radar/4534694 to your computer and use it in GitHub Desktop.
class AccountSignup
def self.new(warden, acccount_params)
account = Subscribem::Account.create(account_params)
account.create_schema
UserSignup.new(warden, account, account.owner)
end
end
require_dependency "subscribem/application_controller"
module Subscribem
class AccountsController < ApplicationController
def new
@account = Subscribem::Account.new
@account.build_owner
end
def create
AccountSignUp.new(env['warden'], params[:account])
flash[:success] = "Your account has been successfully created."
redirect_to subscribem.root_url(:subdomain => account.subdomain)
end
end
end
require 'spec_helper'
describe Subscribem::AccountsController do
context "creates the account's schema" do
let!(:account) { stub_model(Subscribem::Account) }
let!(:owner) { stub_model(Subscribem::User) }
let!(:account_params) { { :account => { :name => "First Account" } } }
specify do
AccountSignUp.should_receive(:new).with(warden, account_params)
post :create, params.merge(:use_route => :subscribem)
end
end
end
class UserSignin
def self.new(warden, account, user)
warden.set_user(user.id, :scope => :user)
warden.set_user(account.id, :scope => :account)
end
end
class UserSignup
def self.new(warden, account, user)
account.users << user
UserSignIn.new(warden, account, user)
end
end
require_dependency "subscribem/application_controller"
module Subscribem
class Account::UsersController < ApplicationController
def new
@user = Subscribem::User.new
end
def create
user = Subscribem::User.create(params[:user])
UserSignUp.new(env['warden'], account, user)
flash[:success] = "You have signed up successfully."
redirect_to root_path
end
end
end
@knewter
Copy link

knewter commented Jan 23, 2013

"createo" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment