require File.dirname(__FILE__) + '/spec_helper' describe "by default a new database" do before :all do @config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] case @config['adapter'] when 'mysql' ActiveRecord::Base.establish_connection(@config) ActiveRecord::Base.connection.create_database('charset_plugin_test') ActiveRecord::Base.establish_connection({:database => 'charset_plugin_test', :adapter => 'mysql', :username => @config['username'], :password => @config['password'], :host => @config['host']}) end end after :all do config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] case config['adapter'] when 'mysql' ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.drop_database('charset_plugin_test') end end it 'should have a character set name to be utf8' do if @config['adapter'] == 'mysql' ActiveRecord::Base.connection.character_set_name.to_s.should ==('utf8') end end it 'should have a collation to be utf8_general_ci' do if @config['adapter'] == 'mysql' ActiveRecord::Base.connection.collation_name.to_s.should ==('utf8_general_ci') end end end describe 'creating a new database with custom charset and collation' do before :all do @config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] case @config['adapter'] when 'mysql' ActiveRecord::Base.establish_connection(@config) ActiveRecord::Base.connection.create_database('charset_plugin_test', {:charset => 'latin1', :collation => 'latin1_bin'}) ActiveRecord::Base.establish_connection({:database => 'charset_plugin_test', :adapter => 'mysql', :username => @config['username'], :password => @config['password'], :host => @config['host']}) end end after :all do config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] case config['adapter'] when 'mysql' ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.drop_database('charset_plugin_test') end end it 'should have created a database with a charset of latin1' do if @config['adapter'] == 'mysql' ActiveRecord::Base.connection.character_set_name.to_s.should ==('latin1') end end it 'should have a collation to be latin1_bin' do if @config['adapter'] == 'mysql' ActiveRecord::Base.connection.collation_name.to_s.should ==('latin1_bin') end end describe 'creating a database by only passing the charset' do before :all do @config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] case @config['adapter'] when 'mysql' ActiveRecord::Base.establish_connection(@config) ActiveRecord::Base.connection.create_database(:charset_plugin_test, {:charset => :latin1}) ActiveRecord::Base.establish_connection({:database => 'charset_plugin_test', :adapter => 'mysql', :username => @config['username'], :password => @config['password'], :host => @config['host']}) end end after :all do config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] case config['adapter'] when 'mysql' ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.drop_database('charset_plugin_test') end end it 'should have autoset a proper collation' do if @config['adapter'] == 'mysql' ActiveRecord::Base.connection.collation_name.to_s.should == 'latin1_swedish_ci' end end end end