-
-
Save tooky/4537009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserSignin | |
def self.new(warden, account, user) | |
warden.set_user(user.id, :scope => :user) | |
warden.set_user(account.id, :scope => :account) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserSignup | |
def self.new(warden, account, user) | |
account.users << user | |
UserSignIn.new(warden, account, user) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment