Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
updates to the installer so things don't break.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cook committed Jan 30, 2009
1 parent 2702dff commit 6994d6d
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 149 deletions.
11 changes: 7 additions & 4 deletions config/environment.rb
Expand Up @@ -20,12 +20,15 @@
# engines
require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')

require "rake"
load "#{RAILS_ROOT}/lib/tasks/ansuz.rake"
Rake::Task["ansuz:create_db_config"].invoke

require 'ansuz'

# All this stuff needs to run before the initializer block, else rails will barf if there is no database.yml
unless( File.exists?( File.join(RAILS_ROOT, "config", "database.yml") ) )
require File.join(RAILS_ROOT, "lib", "ansuz", "installer")
installer = Ansuz::Installer.new( RAILS_ENV )
installer.install
end

# Initialize the Ansuz Plugin Manager instance
Ansuz::PluginManagerInstance = Ansuz::PluginManager.new

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/load_ansuz_task.rb
@@ -1 +1 @@
Rake::Task["ansuz:create_db_config"].invoke
#Rake::Task["ansuz:create_db_config"].invoke
75 changes: 0 additions & 75 deletions db/schema.rb
Expand Up @@ -11,35 +11,6 @@

ActiveRecord::Schema.define(:version => 20090114005523) do

create_table "ansuz_themes", :force => true do |t|
t.string "name"
t.string "repository_url"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "blog_comments", :force => true do |t|
t.string "author"
t.string "email"
t.string "website"
t.text "text"
t.integer "blog_post_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "blog_posts", :force => true do |t|
t.string "title"
t.text "contents"
t.integer "created_by"
t.datetime "created_at"
t.datetime "updated_at"
t.string "url"
t.integer "creator_id"
t.integer "updater_id"
t.integer "deleter_id"
end

create_table "content_section_versions", :force => true do |t|
t.integer "content_section_id"
t.integer "version"
Expand All @@ -58,12 +29,6 @@
t.integer "version", :default => 1
end

create_table "feed_readers", :force => true do |t|
t.string "name"
end

add_index "feed_readers", ["name"], :name => "index_feed_readers_on_name"

create_table "form_builder_responses", :force => true do |t|
t.integer "form_builder_id"
t.datetime "created_at"
Expand Down Expand Up @@ -111,28 +76,6 @@
t.text "description_html"
end

create_table "fyles", :force => true do |t|
t.string "mime_type"
t.string "file_name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "has_settings_settings", :force => true do |t|
t.text "settings"
t.integer "configurable_id"
t.string "configurable_type"
end

create_table "menu_entries", :force => true do |t|
t.string "name"
t.string "link"
t.integer "position"
t.integer "parent_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "moderatorships", :force => true do |t|
t.integer "forum_id"
t.integer "user_id"
Expand Down Expand Up @@ -200,7 +143,6 @@

create_table "photo_albums", :force => true do |t|
t.string "name"
t.string "display_type"
end

create_table "posts", :force => true do |t|
Expand Down Expand Up @@ -239,16 +181,6 @@
t.datetime "updated_at"
end

create_table "scrollable_content_sections", :force => true do |t|
t.integer "scrollable_content_id"
t.string "title"
t.text "contents"
end

create_table "scrollable_contents", :force => true do |t|
t.string "name"
end

create_table "site_settings", :force => true do |t|
t.string "name"
t.string "user_theme_name"
Expand Down Expand Up @@ -279,13 +211,6 @@
add_index "tags", ["name"], :name => "index_tags_on_name"
add_index "tags", ["taggings_count"], :name => "index_tags_on_taggings_count"

create_table "testimonials", :force => true do |t|
t.text "content"
t.string "attributed_to"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "topics", :force => true do |t|
t.integer "forum_id"
t.integer "user_id"
Expand Down
16 changes: 5 additions & 11 deletions lib/ansuz/installer.rb
Expand Up @@ -11,7 +11,7 @@ def initialize(environment = ENV['RAILS_ENV'], stdin = $stdin, stdout = $stdout)
end

def choose_theme(theme_directory = File.join(RAILS_ROOT, "public", "themes"))
FileUtils.mkdir_p( theme_directory ) unless File.directory?( theme_directory )
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")
Expand Down Expand Up @@ -78,8 +78,9 @@ 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 .."
Expand All @@ -97,17 +98,10 @@ def install
migrate_plugins
end

if( User.find(:all, :conditions => ["login = 'admin'"]).empty? )
password = get_user_response_for("[ansuz] Enter a password for the default admin user:","")
create_default_admin_user( password )
else
@stdout.puts "[ansuz] Admin user already exists."
end

# Create public/uploads directory for FCKeditor
create_fckeditor_uploads_dir

self.choose_theme
choose_theme
@state = :installation_complete

@stdout.puts "[ansuz] Finished! Start Ansuz with `script/server` on Linux or `ruby script/server` on Windows."
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/ansuz.rake
Expand Up @@ -15,10 +15,10 @@ namespace :ansuz do
end

desc "Run all the necessary tasks to install Ansuz"
task(:install => :environment) do
task(:install) do
@installer.create_db_config
@installer.install
@installer.state.should = :installation_complete
Rake::Task["utils:create_admin"].invoke # We can't see the ActiveRecord stuff in the installer. What's up with that?

STDOUT.puts "[ansuz] Finished! Start Ansuz with `script/server` on Linux or `ruby script/server` on Windows."
end
Expand Down
82 changes: 42 additions & 40 deletions spec/ansuz_installer_spec.rb
Expand Up @@ -3,46 +3,6 @@

# TODO CHECK FOR NO THEMES!
describe Ansuz::Installer do
describe "choosing a theme" do
before(:each) do
@stdin = StringIO.new("","r+") # Fake STDIN/STDOUT
@stdout = StringIO.new("","r+")
@installer = Ansuz::Installer.new('test', @stdin, @stdout)
@theme_dir = File.join(File.dirname(__FILE__), "test_themes")
FileUtils.mkdir_p( @theme_dir )
FileUtils.touch File.join(@theme_dir, "a_test_theme")
end

it "should show a list of themes available" do
@stdin.write "a_test_theme\n"
@stdin.rewind

@installer.choose_theme( @theme_dir )

@installer.themes.should == ['a_test_theme']

end

it "should set the default theme according to user input" do
@stdin.write "a_test_theme\n"
@stdin.rewind
@installer.choose_theme( @theme_dir )

SiteSetting.find_or_create_by_name(:default).user_theme_name.should == 'a_test_theme'
end

it "should NOT set the default theme according to user input if user typos a theme name" do
@stdin.write "a_invalid_test_theme\n"
@stdin.rewind
@installer.choose_theme( @theme_dir )

SiteSetting.find_or_create_by_name(:default).user_theme_name.should == nil
end

after(:each) do
FileUtils.rm_r(@theme_dir)
end
end

describe "creating a database.yml" do
before(:each) do
Expand Down Expand Up @@ -82,6 +42,7 @@

it "should run all the necessary rake tasks to get ansuz running" do
@installer.install
@installer.state.should == :installation_complete
File.exists?( File.join(RAILS_ROOT, "db", "schema.rb" )).should == true
end

Expand All @@ -93,5 +54,46 @@
end
end
end

describe "choosing a theme" do
before(:each) do
@stdin = StringIO.new("","r+") # Fake STDIN/STDOUT
@stdout = StringIO.new("","r+")
@installer = Ansuz::Installer.new('test', @stdin, @stdout)
@theme_dir = File.join(File.dirname(__FILE__), "test_themes")
FileUtils.mkdir_p( @theme_dir )
FileUtils.touch File.join(@theme_dir, "a_test_theme")
end

it "should show a list of themes available" do
@stdin.write "a_test_theme\n"
@stdin.rewind

@installer.choose_theme( @theme_dir )

@installer.themes.should == ['a_test_theme']

end

it "should set the default theme according to user input" do
@stdin.write "a_test_theme\n"
@stdin.rewind
@installer.choose_theme( @theme_dir )

SiteSetting.find_or_create_by_name(:default).user_theme_name.should == 'a_test_theme'
end

it "should NOT set the default theme according to user input if user typos a theme name" do
@stdin.write "a_invalid_test_theme\n"
@stdin.rewind
@installer.choose_theme( @theme_dir )

SiteSetting.find_or_create_by_name(:default).user_theme_name.should == nil
end

after(:each) do
FileUtils.rm_r(@theme_dir)
end
end
end

@@ -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

This file was deleted.

0 comments on commit 6994d6d

Please sign in to comment.