Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'upstream/1_15' into boot-and-follow
Conflicts:
	card/lib/card/migration.rb
  • Loading branch information
xithan committed Feb 18, 2015
2 parents 9af7886 + 0f91ec7 commit 708b502
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -24,3 +24,4 @@ decko*gem
*.sqlite3
*.DS_Store
*.swp
test_work/*
2 changes: 2 additions & 0 deletions card/db/migrate/20110511221913_require_earlier_migrations.rb
@@ -1,4 +1,6 @@
# -*- encoding : utf-8 -*-
require 'card/version'

class RequireEarlierMigrations < ActiveRecord::Migration
def self.up
fail %{
Expand Down
2 changes: 1 addition & 1 deletion card/db/migrate_core_cards/20141230204340_uri_codename.rb
Expand Up @@ -5,7 +5,7 @@ def up
contentedly do
cardname = 'URI'
codename = cardname.to_name.key
okname = Wagn::Migration.find_unused_name(cardname)
okname = Card::Migration.find_unused_name(cardname)
Card.create! :type_id=>Card::CardtypeID, :name=>okname, :codename=>codename
puts "Name #{cardname} was taken, used #{okname}" if okname != cardname
end
Expand Down
5 changes: 5 additions & 0 deletions card/lib/card.rb
Expand Up @@ -14,6 +14,11 @@ class Card < ActiveRecord::Base
require_dependency 'card/auth'
require_dependency 'card/log'
require_dependency 'card/loader'
require_dependency 'card/content'
require_dependency 'card/action'
require_dependency 'card/act'
require_dependency 'card/change'
require_dependency 'card/reference'

has_many :references_from, :class_name => :Reference, :foreign_key => :referee_id
has_many :references_to, :class_name => :Reference, :foreign_key => :referer_id
Expand Down
1 change: 1 addition & 0 deletions card/lib/card/core_migration.rb
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
require 'card/migration'

class Card::CoreMigration < Card::Migration
@type = :core_cards
Expand Down
20 changes: 14 additions & 6 deletions card/lib/card/migration.rb
@@ -1,6 +1,5 @@
# -*- encoding : utf-8 -*-

require 'card'
require 'card/version'

class Card::Migration < ActiveRecord::Migration
Expand All @@ -12,7 +11,7 @@ class << self
# To avoid repetition a lot of instance methods here just call class methods.
# The subclass Card::CoreMigration needs a different @type so we can't use a
# class variable @@type. It has to be a class instance variable.
# Migrations are subclasses of Wagn::Migration or Wagn::CoreMigration but they
# Migrations are subclasses of Card::Migration or Card::CoreMigration but they
# don't inherit the @type. The method below solves this problem.
def type
@type || (ancestors[1] && ancestors[1].type)
Expand All @@ -28,8 +27,12 @@ def find_unused_name base_name
test_name
end

def paths mig_type=type
Cardio.paths["db/migrate#{schema_suffix type}"].to_a
def migration_paths mig_type=type
Cardio.migration_paths mig_type
end

def schema mig_type=type
Cardio.schema mig_type
end

def schema_suffix mig_type=type
Expand All @@ -45,15 +48,20 @@ def schema_mode mig_type=type
ActiveRecord::Base.table_name_suffix = original_suffix
end

def assume_migrated_upto_version
schema_mode do
ActiveRecord::Schema.assume_migrated_upto_version schema, migration_paths
end
end

def data_path filename=nil
if filename
self.paths.each do |path|
self.migration_paths.each do |path|
path_to_file = File.join path, 'data', filename
return path_to_file if File.exists? path_to_file
end
else
File.join self.paths.first, 'data'
File.join self.migration_paths.first, 'data'
end
end
end
Expand Down
22 changes: 1 addition & 21 deletions card/lib/card/version.rb
Expand Up @@ -2,29 +2,9 @@

module Card::Version
class << self

def release
@@version ||= File.read( File.expand_path '../../../VERSION', __FILE__ ).strip
end

def schema type=nil
File.read( schema_stamp_path type ).strip
end

def schema_stamp_path type
root_dir = ( type == :deck_cards ? Cardio.root : Cardio.gem_root )
stamp_dir = ENV['SCHEMA_STAMP_PATH'] || File.join( root_dir, 'db' )

File.join stamp_dir, "version#{ schema_suffix(type) }.txt"
end

def schema_suffix type
case type
when :core_cards then '_core_cards' # was _cards before !!!
when :deck_cards then '_deck_cards'
else ''
end
end

end
end
5 changes: 0 additions & 5 deletions decko-rails/app/controllers/card_controller.rb
Expand Up @@ -2,11 +2,6 @@

require_dependency 'card'

require_dependency 'card/content'
require_dependency 'card/action'
require_dependency 'card/act'
require_dependency 'card/change'
require_dependency 'card/reference'
require_dependency 'decko/exceptions'
require_dependency 'card/mailer' #otherwise Net::SMTPError rescues can cause problems when error raised comes before Card::Mailer is mentioned

Expand Down
6 changes: 1 addition & 5 deletions decko-rails/config/routes.rb
@@ -1,11 +1,7 @@
# -*- encoding : utf-8 -*-

Rails.application.routes.draw do
Decko::Engine.routes.draw do

if !Rails.env.production? && Object.const_defined?( :JasmineRails )
mount Object.const_get(:JasmineRails).const_get(:Engine) => "/specs"
end

#most common
root :to => 'card#read', :via=>:get
match "#{ Decko::Engine.config.files_web_path }/:id(-:size)-:rev_id.:format" =>
Expand Down
7 changes: 6 additions & 1 deletion decko-rails/spec/controllers/card_controller_spec.rb
@@ -1,11 +1,16 @@
# -*- encoding : utf-8 -*-

describe CardController do
routes { Decko::Engine.routes }

include Capybara::DSL
describe "- route generation" do

it "should recognize type" do
#all_routes = Rails.application.routes.routes
#require 'rails/application/route_inspector'
#warn "rountes#{ENV['CONTROLLER']}:\n" + Rails::Application::RouteInspector.new.format(all_routes, ENV['CONTROLLER'])* "\n"

expect({ :get => "/new/Phrase" }).to route_to( :controller => 'card', :action=>'read', :type=>'Phrase', :view=>'new' )
end

Expand Down Expand Up @@ -296,8 +301,8 @@
expect(response.status).to eq(404)
end
end
describe "unit tests" do

describe "unit tests" do
before do
@simple_card = Card['Sample Basic']
login_as 'joe_user'
Expand Down
1 change: 1 addition & 0 deletions decko-rails/spec/controllers/location_spec.rb
Expand Up @@ -4,6 +4,7 @@
#FIXME - this shouldn't really be with the controller specs

describe CardController, "location test from old integration" do
routes { Decko::Engine.routes }

before do
login_as 'joe_user'
Expand Down
29 changes: 29 additions & 0 deletions test_work/test_wagn_app/script/run_mig.sh
@@ -0,0 +1,29 @@
#!/bin/bash

VER=1.15.pre
DBCFG=../database.yml.local
SEEDSQL=../mdummy_test.sql
cd wagn/
gem build wagn.gemspec
mv *.gem ../card/
cd ../decko-rails
gem build decko.gemspec
mv *.gem ../card/
cd ../card
gem build card.gemspec
gem install *-${VER}.gem
cd ../test_work
rbenv which wagn
echo Generate a wagn app
wagn new test_wagn_app -c --gem-path='../../'
cd test_wagn_app
# load seed db (customize to your database.yml)
echo "Load seed db (enter the pw)"
mysql -u decko_user -p mdummy_test < ${SEEDSQL}
# copy db config (populate .local with you user/pw)
cp ${DBCFG} config/database.yml
echo "migrating"
#RAILS_ENV=test bundle exec rake db:migrate --trace
RAILS_ENV=test bundle exec rake wagn:migrate --trace
#RAILS_ENV=development bundle exec rake db:migrate --trace
#RAILS_ENV=development bundle exec rake wagn:migrate --trace
20 changes: 5 additions & 15 deletions wagn/lib/wagn/application.rb
Expand Up @@ -43,10 +43,6 @@ def inherited(base)
end
end

def approot_is_gemroot?
Wagn.gem_root.to_s == config.root.to_s
end

def add_gem_path paths, path, options={}
gem_path = File.join( Wagn.gem_root, path )
with = options.delete(:with)
Expand All @@ -71,11 +67,13 @@ def add_gem_path paths, path, options={}
config.revisions_per_page = 10
config.request_logger = false

# this needs to be on the application's paths object.
# maybe if we finally understand how these are supposed to be connected in railties we can fix lots of stuff
paths['db/migrate'] = Rails::Paths::Path.new(paths, 'db/migrate', "#{Cardio.gem_root}/db/migrate")
paths = Decko::Engine.config.paths
paths['db/migrate'] = Rails::Paths::Path.new(paths, 'db/migrate', "#{Cardio.gem_root}/db/migrate")
# should we have add_deck_paths for these?
paths['local-mod'] = Rails::Paths::Path.new(paths, 'local-mod', "#{Rails.root}/mod") unless approot_is_gemroot?
paths['db/migrate'] = Rails::Paths::Path.new(paths, "#{Rails.root}/db/migrate")
paths['db/migrate_deck_cards'] = Rails::Paths::Path.new(paths, "#{Rails.root}/db/migrate_cards", "#{Rails.root}/db/migrate_cards")
paths['local-mod'] = Rails::Paths::Path.new(paths, 'local-mod', "#{Rails.root}/mod")
add_gem_path paths, "lib/tasks", :with => "lib/wagn/tasks", :glob => "**/*.rake"
add_gem_path paths, 'gem-assets', :with => 'public/assets'

Expand All @@ -87,14 +85,6 @@ def add_gem_path paths, path, options={}
paths['tmp/set'] = "#{Rails.root}/tmp/set"
paths['tmp/set_pattern'] = "#{Rails.root}/tmp/set_pattern"

# Is this needed?
def load_tasks(app=self)
super
# unless approot_is_gemroot?
# Rake::Task["db:schema:dump"].clear
# end
self
end
end
end

12 changes: 12 additions & 0 deletions wagn/lib/wagn/generators/wagn/templates/config/routes.erb
@@ -0,0 +1,12 @@
# -*- encoding : utf-8 -*-

require 'decko/engine'

Rails.application.routes.draw do
<% if @include_jasmine_engine %>
if !Rails.env.production? && Object.const_defined?( :JasmineRails )
mount Object.const_get(:JasmineRails).const_get(:Engine) => "<%= decko_path %>/specs"
end
<% end %>
mount Decko::Engine => '<%= decko_path %>/'
end
18 changes: 10 additions & 8 deletions wagn/lib/wagn/generators/wagn/wagn_generator.rb
Expand Up @@ -5,18 +5,18 @@ class WagnGenerator < Rails::Generators::AppBase

#class WagnGenerator < Rails::Generators::AppGenerator



source_root File.expand_path('../templates', __FILE__)

argument :decko_path, :required=>false

class_option :database, :type => :string, :aliases => "-d", :default => "mysql",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"

class_option 'core-dev', :type => :boolean, aliases: '-c', :default => false, :group => :runtime,
desc: "Prepare deck for wagn core testing"

class_option 'gem-path', :type => :string, aliases: '-g', :default => false, :group => :runtime,
desc: "Path to local gem installation"
desc: "Path to local gem installation (Default, use env WAGN_DEV_GEM_PATH)"

class_option 'mod-dev', :type => :boolean, aliases: '-m', :default => false, :group => :runtime,
desc: "Prepare deck for mod testing"
Expand All @@ -28,20 +28,22 @@ class WagnGenerator < Rails::Generators::AppBase

## should probably eventually use rails-like AppBuilder approach, but this is a first step.
def dev_setup
@gem_path = options['gem-path']
# TODO: rename or split, gem_path points to the source repo, card and wagn gems are subdirs
@gem_path = options['gem-path'] || "ENV['WAGN_DEV_GEM_PATH']"
@include_jasmine_engine = false
if options['core-dev']
# TODO: rename or split, gem_path points to the source repo, card and wagn gems are subdirs
@gem_path = options['gem-path'] || ask("Enter the path to your local wagn gem installation: ")
@include_jasmine_engine = true
@spec_path = @gem_path
@spec_helper_path = File.join @spec_path, 'card', 'spec', 'spec_helper'
# Will this work when @gem_path is 'ENV[...]' ?
@features_path = File.join @gem_path, 'wagn/features/' # ending slash is important in order to load support and step folders
@simplecov_config = "card_core_dev_simplecov_filters"
template "rspec", ".rspec"
elsif options['mod-dev']
@spec_path = 'mod/'
@spec_helper_path = './spec/spec_helper'
@simplecov_config = "card_simplecov_filters"
@gem_path = options['gem-path'] || ask("Enter the path to your local wagn gem installation: ")
@gem_path = ask("Enter the path to your local wagn gem installation: ") unless @gem_path
@spec_path = @gem_path
@spec_helper_path = File.join @spec_path, 'spec', 'spec_helper'
empty_directory 'spec'
Expand Down Expand Up @@ -73,7 +75,6 @@ def dev_setup
end
end


def rakefile
template "Rakefile"
end
Expand Down Expand Up @@ -126,6 +127,7 @@ def config

inside "config" do
template "application.rb"
template 'routes.erb', "routes.rb"
template "environment.rb"
template "boot.rb"
template "databases/#{options[:database]}.yml", "database.yml"
Expand Down

0 comments on commit 708b502

Please sign in to comment.