diff --git a/.gitignore b/.gitignore index 9a05408..141cd63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config/database.yml +config/database.yml.bak log/ log/* *.swp diff --git a/app/2 b/app/2 deleted file mode 100644 index 181bcfa..0000000 --- a/app/2 +++ /dev/null @@ -1,459 +0,0 @@ -html{ - background-color: #ddd; -} - -body{ - font-family: "Bitstream Vera Sans", Arial, sans-serif; - background-color: #ddd; -} - -h1, h2, h3, h4, h5, h6{ - font-family: Georgia,"Times New Roman",Times,serif; -} - -h1{ - text-align: left; - font-size: 200%; - padding: 10px; -} - -h1.title{ - background-color: #222; - color: white; - font-size: 250%; -} - -h1 a.button2{ - font-family: "Bitstream Vera Sans", Arial, sans-serif; - font-size: 14px; - position: relative; - left: 20px; - top: -5px; -} - -h3{ - font-size: 130%; -} - -em{ - font-weight: 600; -} - -#outside{ - position: relative; -} - -#wrapper{ - position: relative; -} - -#header { - width:100%; - text-align: left; - color: white; - padding: 10px; - height: 40px; -} - -#header h1{ - font-size: 250%; -} - -#toolbar{ - background-color: #ddd; - text-align: left; - position: absolute; - top: 0; - height: 20px; - left: 0; - width: 100%; -} - -#content{ - padding-top: 55px; -} - -#sidebar{ - float: left; - width: 25%; - background-color: #ddd; - text-align: left; -} - -#sidebar h2{ - background-color: #bbb; - padding: 4px; - margin: 4px 0; -} - -#sidebar input.text{ - width: 96%; -} - -#doc2{ - width: 71%; - float: left; - margin-right: 10px; -} - -/* Tabs */ -#hd { - width:100%; - height: 27px; - background: #555; -} - -#hd ul { - float: left; -} - -#hd ul#base-links { - float: right; -} - -#hd ul li { - display:inline; -} - -#hd ul li a, #hd ul li span { - text-decoration: none; - padding: 4px 10px; - background:#555; - color: white; -} - -#hd ul li span { - background:#555; - color: white; -} - -#hd ul li a:hover { - background:#333; -} - -#hd ul li { - text-decoration:none; -} - -#bd { - background:white; - padding:5px; - margin-left: 10px; - border-width: 0 2px 2px 0px; - border-style: solid; - border-color: #aaa; - min-height: 400px; -} - -#bd h1{ - font-size: 200%; - padding: 0; - margin-bottom: 10px; - color: black; -} - -#bd h2{ - font-size: 140%; -} - -label.title_label{ - display: block; -} - -.clear{ clear: both; float: none !important; } - -ul.grid{ - display: block; -} - -ul.grid li.item{ - display: block; - float: left; - width: 214px; - margin-right: 10px; -} - -ul.grid li.item img{ - border: 10px solid #ddd; -} - -ul.grid li.item img:hover { - border: 10px solid #bbb; -} -ul.grid li.item.active img { - border-color: #777; -} -#tree li li:hover { - background-color: #eee; -} - -#admin-menu{ - position: relative; - z-index: 200; - font-size: 1.2em; -} - -#admin-menu li{ - float: left; - position: relative; - width: 150px; - z-index: 100; - margin-right: 20px; -} - -#admin-menu li:hover span{ - background: #333; -} - -#admin-menu li span, #admin-menu li a{ - display: block; - width: 150px; -} -#admin-menu li span{ - cursor: default; -} - -#admin-menu li a span{ - cursor: pointer; -} - -#admin-menu li ul{ - display: none; - padding: 0; - margin: 0; - opacity: .9; -} - -#admin-menu li:hover ul{ - display: block; - background: white; -} - -#admin-menu li ul li a, #admin-menu li ul li span{ - padding: 4px 10px; - border-bottom: 1px solid #333; -} - -#admin-menu li ul li a span, #admin-menu li ul li span span{ - padding: 0; - border: 0; -} - -#admin-menu li span.note{ - margin: 0; - font-size: 75%; - font-style: oblique; - background: transparent; -} - -#admin-menu li li:hover a{ - background-color: #333; -} - -.note{ - margin: 10px 0; - background-color: #ccc; - padding: 10px; -} - -#sidebar > .note:first-child { - margin-top: 0; -} - -#sidebar .form-table th, #sidebar .form-table td{ - border-bottom: 0; -} - -a.button{ - padding: 10px; - color: #444; - text-decoration: none; - width: 200px; - display: block; - font-weight: bold; -} -a.button:hover { - color: black; -} -a.button.icon{ - padding-left: 30px; - width: 180px; - background-repeat: no-repeat; - background-position: 5px 10px; -} -a.button.icon.add{ - background-image: url(/images/famfamfam_icons/add.png) -} -a.button.icon.remove{ - background-image: url(/images/famfamfam_icons/delete.png) -} -a.button.icon.back{ - background-image: url(/images/famfamfam_icons/arrow_left.png) -} -a.button.icon.forward{ - background-image: url(/images/famfamfam_icons/arrow_right.png) -} -a.button.icon.edit{ - background-image: url(/images/famfamfam_icons/pencil.png) -} -a.button.icon.rss{ - background-image: url(/images/famfamfam_icons/rss.png) -} -#tree ul li .page_controls ul.dropdown li{ - float: none; -} - -/* Dropdown menu stuff for 'add page' */ - -div.outerbox{ - font-size: 100%; -} - -div.cmDiv{ - border: 0; -} - -.clickMenu li a{ - margin-right: 0 !important; -} - -.clickMenu li.main{ - font-size: 85%; - padding: 4px; - color: white; - border: 0; -} - -.clickMenu ul{ - border: 0; - background-color: #777; -} - -.clickMenu li.main:hover { - background-color: #444; - cursor: pointer; -} - -.clickMenu li.main li{ - min-width: 120px !important; - padding: 4px; -} - -.clickMenu li.main li a{ - color: white; -} - -li.main ul.innerBox li:hover, .clickMenu li.main ul.innerBox li:hover a { - background-color: #666; -} -.clickMenu li.main ul.innerBox li a{ - display: block; - width: 150px; -} -.clickMenu li.main ul.innerBox li a:hover { - cursor: pointer; -} - -/* End Dropdown menu stuff for 'add page' */ - -.ui-tabs-hide{ display: none; } - - -input.text, textarea{ - font-size: 1.5em; - padding: 4px; - margin-bottom: 1em; -} - -input.button, a.button2{ - background-color: #ccc; - border: 1px solid #aaa; - font-size: 1.2em; - padding: 4px; - text-decoration: none; - color: #333; -} - -input.button:hover, a.button2:hover { - background-color: #bbb; - cursor: pointer; -} -li.clear{ - height: 0 !important; - padding: 0 !important; -} - -#page-plugins-tabs li{ - padding-right:10px; - margin-right:10px; -} -#page-plugins-tabs li.top{ - position: relative; -} -#page-plugins-tabs li.top a.delete{ - position: absolute; - right: 0; - height: 21px; - top: 1px; - cursor: pointer; -} -#page-plugins-tabs li.top a.delete:hover { - background-color: #bbb; -} -#advance_display_options{ - display: none; -} -input, textarea{ - border-style: solid; - border-width: 1px; - border-color: #bbb; -} -input:focus, textarea:focus { - border-color: #888; -} - -.blog-post-form input.title{ - width: 98%; -} -.toggle-content-box{ - margin-bottom: 10px; -} -a.toggle-link{ - padding: 4px; - display: block; - background-color: #555; - color: white; - text-decoration: none; -} -a.toggle-link:hover { - background-color: #444; -} - -#supplemental-nav{ -position:absolute; -top: 0; -right: 0; -} -#supplemental-nav ul li{ -float: left; -margin-right: 20px; -margin-top: 8px; -} -#supplemental-nav ul li a{ -color: white; -text-decoration: none; -padding: 8px 12px; -} -#supplemental-nav ul li a:hover { - background-color: #333; -} -#bd .fullwidth{ - margin: 0 -5px 0 -5px !important; -} -ul.admin_actions li{ - float: left; - padding: 2px 6px; -} -.blog_post p{ - margin-bottom: 1em; -} diff --git a/config/database.yml.bak b/config/database.yml.bak deleted file mode 100644 index ee0a238..0000000 --- a/config/database.yml.bak +++ /dev/null @@ -1,23 +0,0 @@ -# Linux example follows: -development: - adapter: mysql - database: ansuz_development - username: root - password: - host: localhost - #socket: /tmp/mysql.sock - socket: /var/run/mysqld/mysqld.sock - -test: - database: ansuz_test - adapter: mysql - username: root - host: localhost - socket: /var/run/mysqld/mysqld.sock - -production: - adapter: mysql - database: ansuz_production - username: root - password: - host: localhost diff --git a/config/initializers/load_ansuz_task.rb b/config/initializers/load_ansuz_task.rb new file mode 100644 index 0000000..0c5de47 --- /dev/null +++ b/config/initializers/load_ansuz_task.rb @@ -0,0 +1 @@ +#Rake::Task["ansuz:create_db_config"].invoke diff --git a/db/schema.rb b/db/schema.rb index 9ad7eba..fb6c40f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -135,19 +135,6 @@ t.string "configurable_type" end - create_table "media_player_playlist_items", :force => true do |t| - t.integer "media_player_id" - t.string "playlist_item_song_file_name" - t.string "playlist_item_song_content_type" - t.integer "playlist_item_song_file_size" - end - - add_index "media_player_playlist_items", ["media_player_id"], :name => "index_media_player_playlist_items_on_media_player_id" - - create_table "media_players", :force => true do |t| - t.string "name" - end - create_table "menu_entries", :force => true do |t| t.string "name" t.string "link" @@ -194,6 +181,7 @@ t.string "name" t.string "title" t.string "full_title" + t.string "status" t.text "body" t.datetime "created_at" t.datetime "updated_at" @@ -204,7 +192,6 @@ t.boolean "published", :default => true t.boolean "linked", :default => true t.boolean "show_sub_menu", :default => false - t.string "status" t.datetime "publish_at" t.datetime "expires_on" end @@ -227,11 +214,6 @@ t.string "display_type" end - create_table "plugin_schema_info", :id => false, :force => true do |t| - t.string "plugin_name" - t.integer "version" - end - create_table "posts", :force => true do |t| t.integer "user_id" t.integer "topic_id" diff --git a/lib/ansuz/installer.rb b/lib/ansuz/installer.rb index 9a2bba8..c2a6651 100644 --- a/lib/ansuz/installer.rb +++ b/lib/ansuz/installer.rb @@ -7,10 +7,11 @@ def initialize(environment = ENV['RAILS_ENV'], stdin = $stdin, stdout = $stdout) @themes = [] @stdin = stdin @stdout = stdout - @state = :started + @state = :started # this helps with the tests end def choose_theme(theme_directory = File.join(RAILS_ROOT, "public", "themes")) + FileUtils.mkdir_p( theme_directory ) unless File.directory?( theme_directory ) @themes = Dir.entries(theme_directory).select{|d| d =~ /^\w|^\d/}.collect{|theme| theme="- #{theme}"} if( @themes.any? ) @stdout.puts "[ansuz] Themes:\n" + @themes.join("\n") @@ -22,7 +23,11 @@ def choose_theme(theme_directory = File.join(RAILS_ROOT, "public", "themes")) theme = @themes.detect{|t| t == theme_choice} if( theme ) @state = :theme_installed - return SiteSetting.find_or_create_by_name(:default).update_attribute(:user_theme_name, theme) + begin + return SiteSetting.find_or_create_by_name(:default).update_attribute(:user_theme_name, theme) + rescue + STDERR.puts "Badness happened trying to set the default theme. SQLite does this a lot." + end else @state = :invalid_theme @stdout.puts "[ansuz] invalid theme." @@ -34,68 +39,37 @@ def choose_theme(theme_directory = File.join(RAILS_ROOT, "public", "themes")) end end + def get_user_response_for(question, default_response="") + @state = :getting_user_response + @stdout.puts question + @stdin = rewind(@stdin) + response = @stdin.gets.chomp.strip + @state = :got_user_response + if( response.nil? || response.blank? ) + return default_response + else + return response + end + end + def create_db_config(database_yaml_path = File.join(RAILS_ROOT, "config", "database.yml") ) unless( File.exists?( database_yaml_path ) ) - @stdout.puts "[ansuz] Database config does not exist? Would you like one created for you? (Rails will not boot until it has a valid db config)" - @state = :user_wants_database_yaml - response = @stdin.gets.chomp + response = get_user_response_for("[ansuz] Database config does not exist? Would you like one created for you? (Rails will not boot until it has a valid db config)") if( response =~ /^y|^yes/i ) + @state = :user_wants_database_yaml config = { } - @stdout.puts "[ansuz] Database Wizard: Which adapter will the CMS use? ( mysql, sqlite, etc) " - database_adapter = @stdin.gets.chomp.strip - database_adapter = "mysql" if database_adapter.blank? - config["adapter"] = database_adapter.downcase - if( database_adapter != "sqlite" ) - @stdout.puts "[ansuz] Host (localhost):" - database_host = @stdin.gets.chomp.strip - database_host = "localhost" if database_host.blank? - config["host"] = database_host - - @stdout.puts "[ansuz] Username (root):" - database_username = @stdin.gets.chomp.strip - database_username = "root" if database_username.blank? - config["user"] = database_username - - @stdout.puts "[ansuz] Password:" - database_password = @stdin.gets.chomp.strip - database_password = nil if database_password.blank? - config["password"] = database_password - - @stdout.puts "[ansuz] Socket (/var/run/mysqld/mysqld.sock): " - database_socket = @stdin.gets.chomp.strip - database_socket = "/var/run/mysqld/mysqld.sock" if database_socket.blank? - config["socket"] = database_socket - - @stdout.puts "[ansuz] Database Name Prefix (ansuz):" - database_prefix = @stdin.gets.chomp.strip - database_prefix = "ansuz" if database_prefix.blank? - config["database"] = database_prefix + config["adapter"] = get_user_response_for("[ansuz] Database Wizard: Which adapter will the CMS use? ( mysql, sqlite, etc) ", "mysql").downcase + if( config["adapter"] != "sqlite" ) + config["host"] = get_user_response_for("[ansuz] Host (localhost):", "localhost").downcase + config["user"] = get_user_response_for("[ansuz] Username (root):", "root") + config["password"] = get_user_response_for("[ansuz] Password:", nil) + config["socket"] = get_user_response_for("[ansuz] Socket (/var/run/mysqld/mysqld.sock): ", "/var/run/mysqld/mysqld.sock") + config["database"] = get_user_response_for("[ansuz] Database Name Prefix (ansuz):", "ansuz") else - @stdout.puts "[ansuz] Database Location (db/development.sqlite):" - database_location = @stdin.gets.chomp.strip - database_location = "db" if database_location.blank? - config["database"] = database_location - end - - database_config = {} - ["production","development","test"].each do |env| - database_config[env] = {} - config.each_pair do |key,val| - case key - when "database": - database_config[env][key] = val + "_" + env - when "location": - database_config[env][key] = val + "/#{env}.sqlite" - else - database_config[env][key] = val - end - end + config["database"] = get_user_response_for("[ansuz] Database Location (db/development.sqlite):", "db/") end - database_yaml = YAML::dump( database_config ).gsub(/^---/,'') - handle = File.open( File.join(RAILS_ROOT, "config", "database.yml"),"w" ) - handle.puts( database_yaml ) - handle.close + create_config_for_environment(["production","development","test"], config) @state = :database_yaml_created_successfully @stdout.puts "[ansuz] Database configuration created successfully" else @@ -108,55 +82,101 @@ def create_db_config(database_yaml_path = File.join(RAILS_ROOT, "config", "datab def install unless( File.exists?( File.join(RAILS_ROOT, "config", "database.yml") ) ) - @stdout.puts "[ansuz]Please create a config/database.yml file before running this task." - return false + #@stdout.puts "[ansuz]Please create a config/database.yml file before running this task." + #return false + create_db_config end @stdout.puts "[ansuz] Creating database .." Kernel.silence_stream(@stdout) do - # FIXME - # Invoking db tasks causes a rollback of some kind during testing -james - #Rake::Task['db:create:all'].invoke - `rake db:create:all` + create_database end @stdout.puts "[ansuz] Migrating tables .." Kernel.silence_stream(@stdout) do - #Rake::Task['db:migrate'].invoke - `rake db:migrate` + migrate_database end @stdout.puts "[ansuz] Migrating plugins .." Kernel.silence_stream(@stdout) do - #Rake::Task['db:migrate:plugins'].invoke - `rake db:migrate:plugins` + migrate_plugins end - if( User.find(:all, :conditions => ["login = 'admin'"]).empty? ) - @stdout.puts "[ansuz] Enter a password for the default admin user:" - @stdout.flush - password = @stdin.gets.chomp - u = User.new :login => 'admin', :email => 'admin@example.com', :password => password, :password_confirmation => password - u.save - u.has_role 'admin' - u.save # Not sure why we save twice. Josh? - @stdout.puts "[ansuz] Admin user created with login 'admin' and the password you entered." - else - @stdout.puts "[ansuz] Admin user already exists." + # Create public/uploads directory for FCKeditor + create_fckeditor_uploads_dir + + choose_theme + @state = :installation_complete + + + + @stdout.puts "[ansuz] Finished! Start Ansuz with `script/server` on Linux or `ruby script/server` on Windows." + end + + protected + + def create_config_for_environment( environments, config ) + @state = :creating_config + database_config = {} + environments.each do |environment| + database_config[environment] = {} + config.each_pair do |key,val| + case key + when "database": + database_config[environment][key] = val + "_" + environment + when "location": + database_config[environment][key] = val + "/#{environment}.sqlite" + else + database_config[environment][key] = val + end + end end - # Create public/uploads directory for FCKeditor + database_yaml = YAML::dump( database_config ).gsub(/^---/,'') + handle = File.open( File.join(RAILS_ROOT, "config", "database.yml"),"w" ) + handle.puts( database_yaml ) + handle.close + end + + def create_default_admin_user(password) + u = User.new :login => 'admin', :email => 'admin@example.com', :password => password, :password_confirmation => password + u.save + u.has_role 'admin' + u.save + @stdout.puts "[ansuz] Admin user created with login 'admin' and the password you entered." + end + + def create_fckeditor_uploads_dir + @state = :creating_fckeditor_uploads_dir unless( File.directory?( File.join(RAILS_ROOT, "public", "uploads") ) ) @stdout.puts "[ansuz] Creating public/uploads directory for FCKeditor.." - FileUtils.mkdir( File.join(RAILS_ROOT, "public", "uploads") ) + FileUtils.mkdir_p( File.join(RAILS_ROOT, "public", "uploads") ) + @state = :created_fckeditor_uploads_dir + else + @state = :fckeditor_uploads_dir_already_exists end + end - #Rake::Task["ansuz:choose_theme"].invoke - self.choose_theme + def create_database + @state = :creating_databases + system "rake db:create:all" + end - @stdout.puts "[ansuz] Finished! Start Ansuz with `script/server` on Linux or `ruby script/server` on Windows." + def migrate_database + @state = :migrating_database + system "rake db:migrate" end + def migrate_plugins + @state = :migrating_plugins + system "rake db:migrate:plugins" + end + def rewind(io) + if( io.is_a?(StringIO) ) # In non-test environment, we can't seek through STDIN, it gets rewound for us I suppose -james + io.rewind + end + io + end end end diff --git a/lib/tasks/ansuz.rake b/lib/tasks/ansuz.rake index 2db355f..a042485 100644 --- a/lib/tasks/ansuz.rake +++ b/lib/tasks/ansuz.rake @@ -1,145 +1,24 @@ require "yaml" +require File.join(File.dirname(__FILE__), "..","ansuz","installer.rb") +@installer = Ansuz::Installer.new namespace :ansuz do desc "Set the CMS theme" task(:choose_theme => :environment) do - themes = Dir.entries( File.join(RAILS_ROOT, "themes")).select{|d| d =~ /^\w|^\d/}.collect{|theme| theme="- #{theme}"} - if( themes.any? ) - STDOUT.puts "[ansuz] Themes:\n" + themes.join("\n") - STDOUT.puts "[ansuz] Enter a selection above, or leave blank for default" - theme_choice = $stdin.gets.chomp - unless( theme_choice.blank? ) - theme = theme_choice.detect{|t| t == theme_choice} - if( theme ) - SiteSetting.find_or_create_by_name(:default).update_attribute(:user_theme_name, theme) - else - STDOUT.puts "[ansuz] invalid theme." - end - end - else - STDOUT.puts "[ansuz] No themes available!" - end - + @installer.choose_theme end # Called at the beginning of the initializer in config/environment.rb before Rails complains about not having a db" desc "Build a basic database.yml" task(:create_db_config) do - unless( File.exists?( File.join(RAILS_ROOT, "config", "database.yml") ) ) - STDOUT.puts "[ansuz] Database config does not exist? Would you like one created for you? (Rails will not boot until it has a valid db config)" - response = $stdin.gets.chomp - if( response =~ /^y|^yes/i ) - config = { } - STDOUT.puts "[ansuz] Database Wizard: Which adapter will the CMS use? ( mysql, sqlite, etc) " - database_adapter = $stdin.gets.chomp.strip - database_adapter = "mysql" if database_adapter.blank? - config["adapter"] = database_adapter.downcase - if( database_adapter != "sqlite" ) - STDOUT.puts "[ansuz] Host (localhost):" - database_host = $stdin.gets.chomp.strip - database_host = "localhost" if database_host.blank? - config["host"] = database_host - - STDOUT.puts "[ansuz] Username (root):" - database_username = $stdin.gets.chomp.strip - database_username = "root" if database_username.blank? - config["user"] = database_username - - STDOUT.puts "[ansuz] Password:" - database_password = $stdin.gets.chomp.strip - database_password = nil if database_password.blank? - config["password"] = database_password - - STDOUT.puts "[ansuz] Socket (/var/run/mysqld/mysqld.sock): " - database_socket = $stdin.gets.chomp.strip - database_socket = "/var/run/mysqld/mysqld.sock" if database_socket.blank? - config["socket"] = database_socket - - STDOUT.puts "[ansuz] Database Name Prefix (ansuz):" - database_prefix = $stdin.gets.chomp.strip - database_prefix = "ansuz" if database_prefix.blank? - config["database"] = database_prefix - else - STDOUT.puts "[ansuz] Database Location (db/development.sqlite):" - database_location = $stdin.gets.chomp.strip - database_location = "db" if database_location.blank? - config["database"] = database_location - end - - database_config = {} - ["production","development","test"].each do |env| - database_config[env] = {} - config.each_pair do |key,val| - case key - when "database": - database_config[env][key] = val + "_" + env - when "location": - database_config[env][key] = val + "/#{env}.sqlite" - else - database_config[env][key] = val - end - end - end - - database_yaml = YAML::dump( database_config ).gsub(/^---/,'') - handle = File.open( File.join(RAILS_ROOT, "config", "database.yml"),"w" ) - handle.puts( database_yaml ) - handle.close - STDOUT.puts "[ansuz] Database configuration created successfully" - end - end + @installer.create_db_config end desc "Run all the necessary tasks to install Ansuz" - task(:install => :environment) do - - unless( File.exists?( File.join(RAILS_ROOT, "config", "database.yml") ) ) - STDOUT.puts "[ansuz]Please create a config/database.yml file before running this task." - return false - end - - STDOUT.puts "[ansuz] Creating database .." - Kernel.silence_stream(STDOUT) do - # FIXME - # Invoking db tasks causes a rollback of some kind during testing -james - #Rake::Task['db:create:all'].invoke - `rake db:create:all` - end - - STDOUT.puts "[ansuz] Migrating tables .." - Kernel.silence_stream(STDOUT) do - #Rake::Task['db:migrate'].invoke - `rake db:migrate` - end - - STDOUT.puts "[ansuz] Migrating plugins .." - Kernel.silence_stream(STDOUT) do - #Rake::Task['db:migrate:plugins'].invoke - `rake db:migrate:plugins` - end - - if( User.find(:all, :conditions => ["login = 'admin'"]).empty? ) - STDOUT.puts "[ansuz] Enter a password for the default admin user:" - STDOUT.flush - password = $stdin.gets.chomp - u = User.new :login => 'admin', :email => 'admin@example.com', :password => password, :password_confirmation => password - u.has_role 'admin' - u.save - STDOUT.puts "[ansuz] Admin user created with login 'admin' and the password you entered." - else - STDOUT.puts "[ansuz] Admin user already exists." - end - - # Create public/uploads directory for FCKeditor - unless( File.directory?( File.join(RAILS_ROOT, "public", "uploads") ) ) - STDOUT.puts "[ansuz] Creating public/uploads directory for FCKeditor.." - FileUtils.mkdir( File.join(RAILS_ROOT, "public", "uploads") ) - else - STDOUT.puts "[ansuz] public/uploads directory for FCKeditor already exists." - end - - Rake::Task["ansuz:choose_theme"].invoke - + task(:install) do + @installer.create_db_config + @installer.install + system("rake utils:create_admin") STDOUT.puts "[ansuz] Finished! Start Ansuz with `script/server` on Linux or `ruby script/server` on Windows." end diff --git a/spec/ansuz_installer_spec.rb b/spec/ansuz_installer_spec.rb index 0fcf98b..c86d2c5 100644 --- a/spec/ansuz_installer_spec.rb +++ b/spec/ansuz_installer_spec.rb @@ -3,6 +3,60 @@ # TODO CHECK FOR NO THEMES! describe Ansuz::Installer do + + describe "creating a database.yml" do + before(:each) do + @stdin = StringIO.new("","r+") # Fake STDIN + @stdout = StringIO.new("","r+") + @installer = Ansuz::Installer.new('test', @stdin, @stdout ) + @database_yaml_path = File.join(RAILS_ROOT, "config", "database.yml") + @database_yaml_backup_path = File.join(RAILS_ROOT, "config", "database.yml.bak") + + # Don't destroy the database config!! + if( !File.exists?( @database_yaml_backup_path ) && File.exists?( @database_yaml_path ) ) + FileUtils.cp( @database_yaml_path , @database_yaml_backup_path ) + end + + if( File.exists?( @database_yaml_path ) ) + FileUtils.rm( @database_yaml_path ) + end + end + + it "should not continue if the user enters a newline or anything other than y/yes" do + @stdin.write "banjo\n" + @stdin.rewind + @installer.create_db_config + @installer.state.should == :user_doesnt_want_database_yaml + end + + # You may be tempted to use sqlite for tests, but then you'd be in a world of pain. SQLite - is - the - devil + it "should prompt the user if he/she wants a database.yml created for them" do + @stdin.write "y\n" + @installer.create_db_config "pooptown" + @stdin.write "mysql\n" + @stdin.write "localhost" + @stdin.write "root" + @stdin.write "" + @stdin.write "\n" + @installer.state.should == :database_yaml_created_successfully + end + + it "should run all the necessary rake tasks to get ansuz running" do + @stdin.write "y\n" + @installer.install + @installer.state.should == :installation_complete + File.exists?( File.join(RAILS_ROOT, "db", "schema.rb" )).should == true + end + + after(:each) do + @stdout.truncate(0) + @stdin.close_write + if( File.exists?( @database_yaml_backup_path ) && !File.exists?( @database_yaml_path ) ) + FileUtils.cp( @database_yaml_backup_path , @database_yaml_path ) + end + end + end + describe "choosing a theme" do before(:each) do @stdin = StringIO.new("","r+") # Fake STDIN/STDOUT @@ -14,7 +68,7 @@ end it "should show a list of themes available" do - @stdin.write "a_test_theme\n" # We gotta write and rewind, or the method won't see anything + @stdin.write "a_test_theme\n" @stdin.rewind @installer.choose_theme( @theme_dir ) @@ -43,45 +97,5 @@ FileUtils.rm_r(@theme_dir) end end - - describe "creating a database.yml" do - before(:each) do - @stdin = StringIO.new("","r+") # Fake STDIN - @stdout = StringIO.new("","r+") - @installer = Ansuz::Installer.new('test', @stdin, @stdout ) - @database_yaml_path = File.join(RAILS_ROOT, "config", "database.yml") - @database_yaml_backup_path = File.join(RAILS_ROOT, "config", "database.yml.bak") - - # Don't destroy the database config!! - if( !File.exists?( @database_yaml_backup_path ) && File.exists?( @database_yaml_path ) ) - FileUtils.cp( @database_yaml_path , @database_yaml_backup_path ) - end - - if( File.exists?( @database_yaml_path ) ) - FileUtils.rm( @database_yaml_path ) - end - @stdout.truncate(0) - end - - it "should not continue if the user enters a newline or anything other than y/yes" do - @stdin.write "banjo\n" - @stdin.rewind - @installer.create_db_config - @installer.state.should == :user_doesnt_want_database_yaml - end - - it "should prompt the user if he/she wants a database.yml created for them" do - # @stdin.write "yes\n" - # @stdin.rewind - # @installer.create_db_config - # @installer.state.should == :user_wants_database_yaml - end - - after(:each) do - if( File.exists?( @database_yaml_backup_path ) && !File.exists?( @database_yaml_path ) ) - FileUtils.cp( @database_yaml_backup_path , @database_yaml_path ) - end - end - end end diff --git a/vendor/plugins/has_settings/db/migrate/001_create_has_settings_settings.rb b/vendor/plugins/has_settings/db/migrate/001_create_has_settings_settings.rb new file mode 100644 index 0000000..af03652 --- /dev/null +++ b/vendor/plugins/has_settings/db/migrate/001_create_has_settings_settings.rb @@ -0,0 +1,13 @@ +class CreateHasSettingsSettings < ActiveRecord::Migration + def self.up + create_table :has_settings_settings do |t| + t.text :settings + t.integer :configurable_id + t.string :configurable_type + end + end + + def self.down + drop_table :has_settings_settings + end +end diff --git a/vendor/plugins/has_settings/db/migrate/20081220_create_has_settings_settings.rb b/vendor/plugins/has_settings/db/migrate/20081220_create_has_settings_settings.rb deleted file mode 100644 index 5cf4369..0000000 --- a/vendor/plugins/has_settings/db/migrate/20081220_create_has_settings_settings.rb +++ /dev/null @@ -1,16 +0,0 @@ -class CreateHasSettingsSettings < ActiveRecord::Migration - def self.up - begin - create_table :has_settings_settings do |t| - t.text :settings - t.integer :configurable_id - t.string :configurable_type - end - rescue - end - end - - def self.down - drop_table :has_settings_settings - end -end