-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for system models. Fixed errors found.
- Loading branch information
Doug Youch
committed
Jun 21, 2010
1 parent
886b650
commit 425316d
Showing
8 changed files
with
259 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
describe Client do | ||
|
||
reset_system_tables :clients | ||
|
||
it "should be a valid client" do | ||
@client = Client.new | ||
@client.should have(1).errors_on(:name) | ||
@client.should have(0).errors_on(:domain_limit) | ||
@client.should have(0).errors_on(:max_client_users) | ||
@client.should have(0).errors_on(:max_file_storage) | ||
end | ||
|
||
it "should be able to create a new client with just a name" do | ||
@client = Client.create :name => 'New Client' | ||
@client.id.should_not be_nil | ||
|
||
@client.num_databases.should == 0 | ||
@client.domain_limit.should > 0 | ||
@client.can_add_database?.should be_true | ||
@client.num_client_users.should == 0 | ||
@client.max_client_users.should > 0 | ||
@client.available_client_users.should == @client.max_client_users | ||
@client.used_file_storage.should == 0 | ||
@client.max_file_storage.should > 0 | ||
@client.available_file_storage.should == @client.max_file_storage | ||
end | ||
|
||
it "can not create a client with the same name" do | ||
@client = Client.create :name => 'New Client' | ||
@client.id.should_not be_nil | ||
|
||
@client = Client.create :name => 'New Client' | ||
@client.id.should be_nil | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
describe ClientUser do | ||
|
||
reset_system_tables :clients, :client_users, :domains, :domain_databases | ||
reset_domain_tables :end_users | ||
|
||
it "should be a valid client user" do | ||
@user = ClientUser.new | ||
@user.should have(1).errors_on(:username) | ||
@user.should have(1).errors_on(:client_id) | ||
end | ||
|
||
it "should be able to create a client user" do | ||
@client = Client.create :name => 'New Client' | ||
@client.id.should_not be_nil | ||
@user = @client.client_users.create :username => 'my_test_user' | ||
@user.id.should_not be_nil | ||
|
||
@user = @client.client_users.create :username => 'my_test_user' | ||
@user.id.should be_nil | ||
end | ||
|
||
it "should be able to setup the password and login" do | ||
@client = Client.create :name => 'New Client' | ||
@client.id.should_not be_nil | ||
@user = @client.client_users.create :username => 'my_test_user', :password => 'salt-this' | ||
@user.id.should_not be_nil | ||
@user.hashed_password.should_not be_nil | ||
@user.salt.should_not be_nil | ||
|
||
@user.name.should == 'my_test_user' | ||
@user.identifier_name.should == "CLIENT USER:#{@user.username} (#{@user.id})" | ||
@user.validate_password('unknown').should be_false | ||
@user.validate_password('salt-this').should be_true | ||
|
||
@user = ClientUser.login_by_name 'my_test_user', 'unknown', @client.id | ||
@user.should be_nil | ||
|
||
@user = ClientUser.login_by_name 'my_test_user', 'salt-this', @client.id | ||
@user.should_not be_nil | ||
|
||
@user.password = 'new-password' | ||
@user.save | ||
|
||
@user = ClientUser.login_by_name 'my_test_user', 'salt-this', @client.id | ||
@user.should be_nil | ||
|
||
@user = ClientUser.login_by_name 'my_test_user', 'new-password', @client.id | ||
@user.should_not be_nil | ||
end | ||
|
||
it "should create an end user" do | ||
@domain = Domain.find CMS_DEFAULTS['testing_domain'] | ||
@domain.id.should_not be_nil | ||
@user = @domain.client.client_users.create :username => 'my_test_user', :password => 'salt-this' | ||
@user.id.should_not be_nil | ||
|
||
assert_difference 'EndUser.count', 1 do | ||
@end_user = @user.end_user | ||
end | ||
|
||
@end_user.client_user_id.should == @user.id | ||
|
||
@user = ClientUser.find @user.id | ||
assert_difference 'EndUser.count', 0 do | ||
@end_user = @user.end_user | ||
end | ||
|
||
@end_user.client_user_id.should == @user.id | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
describe DomainDatabase do | ||
|
||
reset_system_tables :domains, :clients, :domain_databases | ||
|
||
it "should be a valid domain database" do | ||
@db = DomainDatabase.new | ||
@db.valid? | ||
@db.should have(1).errors_on(:name) | ||
@db.should have(1).errors_on(:client_id) | ||
end | ||
|
||
it "should be to create a domain database" do | ||
@client = Client.create :name => 'New Client' | ||
@db = DomainDatabase.create :name => 'webiva_001_test_dev', :client_id => @client.id | ||
@db.id.should_not be_nil | ||
|
||
@db = DomainDatabase.create :name => 'webiva_001_test_dev', :client_id => @client.id | ||
@db.id.should be_nil | ||
end | ||
|
||
it "should not allow an invalid max_file_storage" do | ||
@client = Client.create :name => 'New Client' | ||
@db = DomainDatabase.create :name => 'test_webiva_001_test_dev', :client_id => @client.id, :max_file_storage => @client.max_file_storage + 1 | ||
@db.id.should be_nil | ||
end | ||
|
||
it "should set the options to the yml file if it exists" do | ||
database_file = "#{RAILS_ROOT}/config/sites/test_webiva_001_test_dev.yml" | ||
File.unlink(database_file) if File.exists?(database_file) # incase this test failed previously | ||
|
||
@client = Client.create :name => 'New Client' | ||
@db = DomainDatabase.create :name => 'test_webiva_001_test_dev', :client_id => @client.id | ||
@db.id.should_not be_nil | ||
@db.options.should be_nil | ||
|
||
output = {'production' => {'host' => 'localhost', 'username' => 'test', 'password' => ''}} | ||
File.open(database_file,"w") { |fd| fd.write(YAML.dump(output)) } | ||
@db.options.should_not be_nil | ||
@db.options['production']['host'].should == 'localhost' | ||
|
||
File.unlink database_file | ||
@db.reload | ||
@db.options['production']['host'].should == 'localhost' | ||
end | ||
|
||
it "should be able to get the first domain" do | ||
@client = Client.create :name => 'New Client' | ||
@db = @client.domain_databases.create :name => 'test_webiva_001_test_dev' | ||
@db.id.should_not be_nil | ||
@db.first_domain.should be_nil | ||
@db.domain_name.should == 'test_webiva_001_test_dev' | ||
|
||
@domain = @client.domains.create :name => 'test-webiva.dev', :domain_database_id => @db.id | ||
@domain.id.should_not be_nil | ||
|
||
@db.reload | ||
@db.first_domain.id.should == @domain.id | ||
@db.domain_name.should == 'test-webiva.dev' | ||
end | ||
|
||
it "should be clearing the domain info cache after saving" do | ||
@client = Client.create :name => 'New Client' | ||
@db = @client.domain_databases.create :name => 'test_webiva_001_test_dev' | ||
@db.id.should_not be_nil | ||
@domain = @client.domains.create :name => 'test-webiva.dev', :domain_database_id => @db.id | ||
@domain.id.should_not be_nil | ||
|
||
@db.reload | ||
|
||
DataCache.should_receive(:set_domain_info).with('test-webiva.dev', nil) | ||
@db.update_attribute(:max_file_storage, 2) | ||
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