Browse Source

domain and subdomain ownership wiring

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
489abcd698
  1. 2
      app/controllers/domains_controller.rb
  2. 1
      app/models/domain.rb
  3. 36
      spec/controllers/domains_controller_spec.rb

2
app/controllers/domains_controller.rb

@ -31,7 +31,7 @@ class DomainsController < ApplicationController
def before_create_save(record)
record.type = 'NATIVE'
record.user = current_user
record.user = record.parent_domain.present? ? record.parent_domain.user : current_user
end
def after_create_save(record)

1
app/models/domain.rb

@ -56,6 +56,7 @@ class Domain < ActiveRecord::Base
end
def parent_domain
return nil if name.nil?
@parent_domain ||= {}
@parent_domain[name] ||= begin
segments = name.split('.')

36
spec/controllers/domains_controller_spec.rb

@ -1,7 +1,41 @@
require 'spec_helper'
describe DomainsController do
it_should_behave_like "wiring controller"
context "wiring" do
include_context "data"
# a domain who's parent domain is not in our system
context "domain" do
before do
sign_in user
end
it "is wired with the current user by #new_model" do
@controller.send(:new_model).user.should == user
end
it "is wired with the current user by #before_create_save" do
domain = build(:domain)
@controller.send(:before_create_save, domain)
domain.user.should == user
end
end
# a domain who's parent domain is in our system
context "subdomain" do
before do
sign_in other_user
end
it "is wired with the user of the parent domain by #before_create_save" do
subdomain = build(:domain, :user => other_user, :name => "x.#{domain.name}")
@controller.send(:before_create_save, subdomain)
subdomain.user.should == user
end
end
end
end
# TODO implement me

Loading…
Cancel
Save