Sha256: 3d83e842a2a36aab09825cf7c649e2989a9f29982e5120c320123e1be653ee51

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

describe "ActiveRecord::Base" do
  before(:each) do
    ActionController::Routing::Routes.clear!
    SubdomainRoutes::Config.stub!(:domain_length).and_return(2)
    class User < ActiveRecord::Base
      attr_accessor :subdomain
    end
  end

  it "should have validates_subdomain_format_of which runs SubdomainRoutes.valid_subdomain? against the attributes" do
    User.validates_subdomain_format_of :subdomain
    SubdomainRoutes.should_receive(:valid_subdomain?).with("mholling").and_return(true)
    User.new(:subdomain => "mholling").should be_valid
    SubdomainRoutes.should_receive(:valid_subdomain?).with("mholling").and_return(nil)
    User.new(:subdomain => "mholling").should_not be_valid
  end
  
  it "should have validates_subdomain_not_reserved which checks the attributes against the fixed-subdomain routes" do
    User.validates_subdomain_not_reserved :subdomain
    reserved = [ "", "www", "support", "admin" ]
    map_subdomain(*reserved) { |map| map.resource :home }
    reserved.each do |subdomain|
      User.new(:subdomain => subdomain).should_not be_valid
    end
    [ "mholling", "edmondst" ].each do |subdomain|
      User.new(:subdomain => subdomain).should be_valid
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mholling-subdomain_routes-0.2.0 spec/validations_spec.rb