wagn 1.17.4 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +14 -17
  3. data/bin/wagn +2 -2
  4. data/features/step_definitions/email_steps.rb +14 -17
  5. data/features/step_definitions/history_steps.rb +1 -1
  6. data/features/step_definitions/wagn_steps.rb +5 -11
  7. data/features/step_definitions/web_steps.rb +10 -15
  8. data/features/step_definitions/window_steps.rb +7 -7
  9. data/features/support/env.rb +3 -3
  10. data/features/support/paths.rb +13 -13
  11. data/features/support/scopes.rb +2 -2
  12. data/lib/decko/engine.rb +9 -12
  13. data/lib/wagn/cli.rb +4 -4
  14. data/lib/wagn/commands.rb +20 -24
  15. data/lib/wagn/commands/application.rb +4 -4
  16. data/lib/wagn/config/environments/cucumber.rb +0 -1
  17. data/lib/wagn/config/environments/development.rb +17 -20
  18. data/lib/wagn/config/environments/production.rb +3 -5
  19. data/lib/wagn/config/environments/profile.rb +2 -3
  20. data/lib/wagn/config/environments/test.rb +8 -9
  21. data/lib/wagn/generators/wagn/templates/bin/spring +7 -7
  22. data/lib/wagn/generators/wagn/templates/spec/spec_helper.rb +1 -1
  23. data/lib/wagn/generators/wagn/wagn_generator.rb +126 -160
  24. data/lib/wagn/generators/wagn/wagn_generator/interactive.rb +0 -0
  25. data/lib/wagn/mods_spec_helper.rb +10 -19
  26. data/lib/wagn/parser.rb +3 -3
  27. data/lib/wagn/script_wagn_loader.rb +6 -6
  28. data/lib/wagn/simplecov_helper.rb +16 -17
  29. data/lib/wagn/tasks/cucumber.rake +12 -15
  30. data/lib/wagn/tasks/db.rake +7 -12
  31. data/lib/wagn/tasks/test.rake +24 -28
  32. data/lib/wagn/tasks/wagn.rake +54 -57
  33. data/rails/application-routes.rb +2 -2
  34. data/rails/controllers/card_controller.rb +4 -6
  35. data/rails/engine-routes.rb +9 -13
  36. data/script/autospec +1 -1
  37. data/script/rails +1 -1
  38. data/script/test_filter +8 -8
  39. data/spec/controllers/card_controller_spec.rb +138 -155
  40. data/spec/controllers/location_spec.rb +8 -13
  41. data/spec/javascripts/support/jasmine_config.rb +6 -9
  42. data/spec/javascripts/support/jasmine_runner.rb +3 -3
  43. data/test/performance/card_create_test.rb +2 -3
  44. data/test/performance/fetch_test.rb +2 -2
  45. data/test/performance/homepage_test.rb +1 -1
  46. data/test/performance/render_test.rb +1 -1
  47. data/test/test_helper.rb +26 -30
  48. data/wagn.gemspec +10 -11
  49. metadata +5 -4
@@ -1,16 +1,15 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require "codeclimate-test-reporter"
2
+ require 'codeclimate-test-reporter'
3
3
  CodeClimate::TestReporter.start
4
4
  require 'spork'
5
5
 
6
- ENV["RAILS_ENV"] = 'test'
6
+ ENV['RAILS_ENV'] = 'test'
7
7
 
8
8
  Spork.prefork do
9
-
10
- if ENV["RAILS_ROOT"]
11
- require File.join( ENV["RAILS_ROOT"], '/config/environment')
9
+ if ENV['RAILS_ROOT']
10
+ require File.join(ENV['RAILS_ROOT'], '/config/environment')
12
11
  else
13
- require File.expand_path( '../../config/environment', __FILE__ )
12
+ require File.expand_path('../../config/environment', __FILE__)
14
13
  end
15
14
  require File.join Cardio.gem_root, 'lib', 'card', 'simplecov_helper.rb'
16
15
 
@@ -18,28 +17,24 @@ Spork.prefork do
18
17
  Bundler.require(:test) # if simplecov is activated in the Gemfile, it has to be required here
19
18
  end
20
19
 
21
-
22
-
23
20
  require 'rspec/rails'
24
21
 
25
22
  # Requires supporting ruby files with custom matchers and macros, etc,
26
23
  # in spec/support/ and its subdirectories.
27
- # Dir[ File.join(Wagn.gem_root, "spec/support/**/*.rb") ].each { |f| require f }
24
+ # Dir[ File.join(Wagn.gem_root, "spec/support/**/*.rb") ].each { |f| require f }
28
25
 
29
- # FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
26
+ # FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
30
27
  JOE_USER_ID = Card['joe_user'].id
31
28
 
32
29
  RSpec.configure do |config|
33
- config.include RSpec::Rails::Matchers::RoutingMatchers, {
34
- file_path: /\bspec\/controllers\//
35
- }
30
+ config.include RSpec::Rails::Matchers::RoutingMatchers, file_path: /\bspec\/controllers\//
36
31
  config.infer_spec_type_from_file_location!
37
32
  # format_index = ARGV.find_index {|arg| arg =~ /--format/ }
38
33
  # formatter = format_index ? ARGV[ format_index + 1 ] : 'documentation'
39
34
  # config.add_formatter formatter
40
35
 
41
- #config.include CustomMatchers
42
- #config.include ControllerMacros, type: :controllers
36
+ # config.include CustomMatchers
37
+ # config.include ControllerMacros, type: :controllers
43
38
 
44
39
  # == Mock Framework
45
40
  # If you prefer to mock with mocha, flexmock or RR, uncomment the appropriate symbol:
@@ -50,7 +45,6 @@ Spork.prefork do
50
45
  config.use_transactional_fixtures = true
51
46
  config.use_instantiated_fixtures = false
52
47
 
53
-
54
48
  config.before(:each) do
55
49
  Card::Auth.current_id = JOE_USER_ID
56
50
  Card::Cache.restore
@@ -62,7 +56,6 @@ Spork.prefork do
62
56
  end
63
57
  end
64
58
 
65
-
66
59
  Spork.each_run do
67
60
  # This code will be run each time you run your specs.
68
61
  end
@@ -70,5 +63,3 @@ end
70
63
  require File.join Cardio.gem_root, 'lib', 'card', 'spec_helper.rb'
71
64
 
72
65
  RSpec::Core::ExampleGroup.send :include, Card::SpecHelper
73
-
74
-
@@ -54,9 +54,9 @@ module Wagn
54
54
  parser.on('-m', '--mod MODNAME',
55
55
  'Run all specs for a mod or matching a mod') do |file|
56
56
  opts[:files] =
57
- if File.exists?("mod/#{file}")
57
+ if File.exist?("mod/#{file}")
58
58
  "#{Cardio.gem_root}/mod/#{file}"
59
- elsif File.exists?("#{Cardio.gem_root}/mod/#{file}")
59
+ elsif File.exist?("#{Cardio.gem_root}/mod/#{file}")
60
60
  "#{Cardio.gem_root}/mod/#{file}"
61
61
  elsif (files = find_spec_file(file, 'mod')) && files.present?
62
62
  files
@@ -78,7 +78,7 @@ module Wagn
78
78
  if spring
79
79
  opts[:executer] = 'spring'
80
80
  if opts[:rescue]
81
- opts[:rescue] = ''
81
+ opts[:rescue] = ''
82
82
  puts 'Disabled pry-rescue. Not compatible with spring.'
83
83
  end
84
84
  else
@@ -2,14 +2,14 @@ require 'pathname'
2
2
 
3
3
  module Wagn
4
4
  module ScriptWagnLoader
5
- RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
5
+ RUBY = File.join(*RbConfig::CONFIG.values_at('bindir', 'ruby_install_name')) + RbConfig::CONFIG['EXEEXT']
6
6
  SCRIPT_WAGN = File.join('script', 'wagn')
7
7
 
8
8
  def self.exec_script_wagn!
9
9
  cwd = Dir.pwd
10
10
  return unless in_wagn_application? || in_wagn_application_subdirectory?
11
11
  exec RUBY, SCRIPT_WAGN, *ARGV if in_wagn_application?
12
- Dir.chdir("..") do
12
+ Dir.chdir('..') do
13
13
  # Recurse in a chdir block: if the search fails we want to be sure
14
14
  # the application is generated in the original working directory.
15
15
  exec_script_wagn! unless cwd == Dir.pwd
@@ -19,11 +19,11 @@ module Wagn
19
19
  end
20
20
 
21
21
  def self.in_wagn_application?
22
- File.exists?(SCRIPT_WAGN)
22
+ File.exist?(SCRIPT_WAGN)
23
23
  end
24
24
 
25
- def self.in_wagn_application_subdirectory?(path = Pathname.new(Dir.pwd))
26
- File.exists?(File.join(path, SCRIPT_WAGN)) || !path.root? && in_wagn_application_subdirectory?(path.parent)
25
+ def self.in_wagn_application_subdirectory? path=Pathname.new(Dir.pwd)
26
+ File.exist?(File.join(path, SCRIPT_WAGN)) || !path.root? && in_wagn_application_subdirectory?(path.parent)
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -2,31 +2,30 @@ def card_simplecov_filters
2
2
  add_filter 'spec/'
3
3
  add_filter '/config/'
4
4
  add_filter '/tasks/'
5
-
6
- # filter all card mods
5
+
6
+ # filter all card mods
7
7
  add_filter do |src_file|
8
- src_file.filename =~ /tmp\// and not
9
- /\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/**/#{m[1]}"].present? }
8
+ src_file.filename =~ /tmp\// && !/\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/**/#{m[1]}"].present? }
10
9
  end
11
-
12
- # add group for each deck mod
13
- Dir['mod/*'].map{ |path| path.sub('mod/','') }.each do |mod|
10
+
11
+ # add group for each deck mod
12
+ Dir['mod/*'].map { |path| path.sub('mod/', '') }.each do |mod|
14
13
  add_group mod.capitalize do |src_file|
15
- src_file.filename =~ /mod\/#{mod}\// or
14
+ src_file.filename =~ /mod\/#{mod}\// ||
16
15
  (
17
- src_file.filename =~ /tmp\// and
18
- /\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/#{mod}/**/#{m[1]}"].present? }
16
+ src_file.filename =~ /tmp\// &&
17
+ /\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/#{mod}/**/#{m[1]}"].present? }
19
18
  )
20
19
  end
21
20
  end
22
21
 
23
22
  add_group 'Sets' do |src_file|
24
- src_file.filename =~ /tmp\/set\// and
25
- /\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/**/#{m[1]}"].present? }
23
+ src_file.filename =~ /tmp\/set\// &&
24
+ /\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/**/#{m[1]}"].present? }
26
25
  end
27
26
  add_group 'Set patterns' do |src_file|
28
- src_file.filename =~ /tmp\/set_pattern\// and
29
- /\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/**/#{m[1]}"].present? }
27
+ src_file.filename =~ /tmp\/set_pattern\// &&
28
+ /\d+-(.+\.rb)/.match(src_file.filename) { |m| Dir["mod/**/#{m[1]}"].present? }
30
29
  end
31
30
  add_group 'Formats' do |src_file|
32
31
  src_file.filename =~ /mod\/[^\/]+\/formats/
@@ -40,8 +39,8 @@ def card_core_dev_simplecov_filters
40
39
  filters.clear # This will remove the :root_filter that comes via simplecov's defaults
41
40
  add_filter do |src|
42
41
  !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /wagn/
43
- end
44
-
42
+ end
43
+
45
44
  add_filter '/spec/'
46
45
  add_filter '/features/'
47
46
  add_filter '/config/'
@@ -49,7 +48,7 @@ def card_core_dev_simplecov_filters
49
48
  add_filter '/generators/'
50
49
  add_filter 'lib/card'
51
50
 
52
- add_group 'Card', 'lib/card'
51
+ add_group 'Card', 'lib/card'
53
52
  add_group 'Set Patterns', 'tmp/set_pattern/'
54
53
  add_group 'Sets', 'tmp/set/'
55
54
  add_group 'Formats' do |src_file|
@@ -4,52 +4,49 @@
4
4
  # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
5
  # files.
6
6
 
7
+ unless ARGV.any? { |a| a =~ /^gems/ } # Don't load anything when running the gems:* tasks
7
8
 
8
- unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
-
10
- vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
9
+ vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
10
  $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
11
 
13
12
  begin
14
13
  require 'cucumber/rake/task'
15
14
 
16
15
  namespace :cucumber do
17
- Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
16
+ Cucumber::Rake::Task.new({ ok: 'db:test:prepare' }, 'Run features that should pass') do |t|
18
17
  t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
18
  t.fork = true # You may get faster startup if you set this to false
20
19
  t.profile = 'default'
21
20
  end
22
21
 
23
- Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
22
+ Cucumber::Rake::Task.new({ wip: 'db:test:prepare' }, 'Run features that are being worked on') do |t|
24
23
  t.binary = vendored_cucumber_bin
25
24
  t.fork = true # You may get faster startup if you set this to false
26
25
  t.profile = 'wip'
27
26
  end
28
27
 
29
- Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
28
+ Cucumber::Rake::Task.new({ rerun: 'db:test:prepare' }, 'Record failing features and run only them if any exist') do |t|
30
29
  t.binary = vendored_cucumber_bin
31
30
  t.fork = true # You may get faster startup if you set this to false
32
31
  t.profile = 'rerun'
33
32
  end
34
33
 
35
34
  desc 'Run all features'
36
- task :all => [:ok, :wip]
35
+ task all: [:ok, :wip]
37
36
 
38
37
  task :statsetup do
39
38
  require 'rails/code_statistics'
40
39
  ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41
- ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42
- ::STATS_DIRECTORIES << %w(Mods mods) if File.exist?('mods') #hack! should be elsewhere
43
-
44
-
40
+ ::CodeStatistics::TEST_TYPES << 'Cucumber features' if File.exist?('features')
41
+ ::STATS_DIRECTORIES << %w(Mods mods) if File.exist?('mods') # hack! should be elsewhere
45
42
  end
46
43
  end
47
44
  desc 'Alias for cucumber:ok'
48
- task :cucumber => 'cucumber:ok'
45
+ task cucumber: 'cucumber:ok'
49
46
 
50
- task :default => :cucumber
47
+ task default: :cucumber
51
48
 
52
- task :features => :cucumber do
49
+ task features: :cucumber do
53
50
  STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
54
51
  end
55
52
 
@@ -57,7 +54,7 @@ begin
57
54
  task 'db:test:prepare' do
58
55
  end
59
56
 
60
- task :stats => 'cucumber:statsetup'
57
+ task stats: 'cucumber:statsetup'
61
58
  rescue LoadError
62
59
  desc 'cucumber rake task not available (cucumber not installed)'
63
60
  task :cucumber do
@@ -7,12 +7,11 @@ require 'rake'
7
7
  unless Rake::TaskManager.methods.include?(:redefine_task)
8
8
  module Rake
9
9
  module TaskManager
10
-
11
- def redefine_task(task_class, args, &block)
10
+ def redefine_task task_class, args, &block
12
11
  task_name, arg_names, deps = resolve_args(args)
13
12
  task_name = task_class.scope_name(@scope, task_name)
14
13
  deps = [deps] unless deps.respond_to?(:to_ary)
15
- deps = deps.collect {|d| d.to_s }
14
+ deps = deps.map(&:to_s)
16
15
  task = @tasks[task_name.to_s] = task_class.new(task_name, self)
17
16
  task.application = self
18
17
  @last_comment = nil
@@ -22,7 +21,7 @@ unless Rake::TaskManager.methods.include?(:redefine_task)
22
21
  end
23
22
  class Task
24
23
  class << self
25
- def redefine_task(args, &block)
24
+ def redefine_task args, &block
26
25
  Rake.application.redefine_task(self, [args], &block)
27
26
  end
28
27
  end
@@ -30,13 +29,12 @@ unless Rake::TaskManager.methods.include?(:redefine_task)
30
29
  end
31
30
  end
32
31
 
33
-
34
32
  namespace :db do
35
33
  namespace :fixtures do
36
34
  desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
37
- task :load => :environment do
35
+ task load: :environment do
38
36
  require 'active_record/fixtures'
39
- fixture_path = File.join(Cardio.gem_root, 'db','seed', 'test', 'fixtures')
37
+ fixture_path = File.join(Cardio.gem_root, 'db', 'seed', 'test', 'fixtures')
40
38
  ActiveRecord::Base.establish_connection(::Rails.env.to_sym)
41
39
  (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(fixture_path, '*.{yml,csv}'))).each do |fixture_file|
42
40
  ActiveRecord::FixtureSet.create_fixtures(fixture_path, File.basename(fixture_file, '.*'))
@@ -46,15 +44,12 @@ namespace :db do
46
44
 
47
45
  namespace :test do
48
46
  desc 'Prepare the test database and load the schema'
49
- Rake::Task.redefine_task( :prepare => :environment ) do
47
+ Rake::Task.redefine_task(prepare: :environment) do
50
48
  if ENV['RELOAD_TEST_DATA'] == 'true' || ENV['RUN_CODE_RUN']
51
49
  puts `env RAILS_ENV=test rake wagn:seed`
52
50
  else
53
- puts "skipping loading test data. to force, run `env RELOAD_TEST_DATA=true rake db:test:prepare`"
51
+ puts 'skipping loading test data. to force, run `env RELOAD_TEST_DATA=true rake db:test:prepare`'
54
52
  end
55
53
  end
56
54
  end
57
55
  end
58
-
59
-
60
-
@@ -1,9 +1,9 @@
1
1
  TEST_SEED_PATH = File.join(
2
- ENV['DECKO_SEED_REPO_PATH'] || [Cardio.gem_root, 'db','seed'], 'test'
2
+ ENV['DECKO_SEED_REPO_PATH'] || [Cardio.gem_root, 'db', 'seed'], 'test'
3
3
  )
4
4
 
5
5
  namespace :test do
6
- task :all => :environment do
6
+ task all: :environment do
7
7
  puts 'This is not yet working; only first invocation takes effect'
8
8
  Rake::Task['test:functionals'].invoke
9
9
  puts 'put 2'
@@ -17,43 +17,40 @@ namespace :test do
17
17
 
18
18
  ## FIXME: this generates an "Adminstrator links" card with the wrong reader_id, I have been
19
19
  ## setting it by hand after fixture generation.
20
- desc "recreate test fixtures from fresh db"
21
- task :generate_fixtures => :environment do
20
+ desc 'recreate test fixtures from fresh db'
21
+ task generate_fixtures: :environment do
22
22
  ENV['GENERATE_FIXTURES'] = 'true'
23
- raise "must be test env" unless Rails.env == 'test'
23
+ raise 'must be test env' unless Rails.env == 'test'
24
24
 
25
25
  Rake::Task['wagn:reset_cache']
26
26
 
27
- puts "reseed test db"
27
+ puts 'reseed test db'
28
28
  Rake::Task['wagn:seed'].invoke
29
29
 
30
- puts ">>populating test data"
30
+ puts '>>populating test data'
31
31
  puts `rake test:populate_template_database --trace`
32
32
 
33
- puts ">>extracting to fixtures"
33
+ puts '>>extracting to fixtures'
34
34
  puts `rake test:extract_fixtures --trace`
35
35
  end
36
36
 
37
+ desc 'dump current db to test fixtures'
38
+ task extract_fixtures: :environment do
39
+ raise 'must be test env' unless Rails.env == 'test'
40
+ YAML::ENGINE.yamler = 'syck' if RUBY_VERSION !~ /^(2|1\.9)/
41
+ # use old engine while we're supporting ruby 1.8.7 because it can't support Psych,
42
+ # which dumps with slashes that syck can't understand (also !!null stuff)
37
43
 
38
- desc "dump current db to test fixtures"
39
- task :extract_fixtures => :environment do
40
- raise "must be test env" unless Rails.env == 'test'
41
- if RUBY_VERSION !~ /^(2|1\.9)/
42
- YAML::ENGINE.yamler = 'syck'
43
- end
44
- # use old engine while we're supporting ruby 1.8.7 because it can't support Psych,
45
- # which dumps with slashes that syck can't understand (also !!null stuff)
46
-
47
- sql = "SELECT * FROM %s"
48
- tables = %w{ cards card_acts card_actions card_changes card_references }
44
+ sql = 'SELECT * FROM %s'
45
+ tables = %w( cards card_acts card_actions card_changes card_references )
49
46
  ActiveRecord::Base.establish_connection
50
47
  tables.each do |table_name|
51
- i = "000"
52
- File.open("#{ TEST_SEED_PATH }/fixtures/#{table_name}.yml", 'w') do |file|
48
+ i = '000'
49
+ File.open("#{TEST_SEED_PATH}/fixtures/#{table_name}.yml", 'w') do |file|
53
50
  data = ActiveRecord::Base.connection.select_all(sql % table_name)
54
51
  file.write data.inject({}) { |hash, record|
55
- record['trash'] = false if record.has_key? 'trash'
56
- record['draft'] = false if record.has_key? 'draft'
52
+ record['trash'] = false if record.key? 'trash'
53
+ record['draft'] = false if record.key? 'draft'
57
54
  hash["#{table_name}_#{i.succ!}"] = record
58
55
  hash
59
56
  }.to_yaml
@@ -61,12 +58,11 @@ namespace :test do
61
58
  end
62
59
  end
63
60
 
64
- desc "create sample data for testing"
65
- task :populate_template_database => :environment do
66
- raise "must be test env" unless Rails.env == 'test'
61
+ desc 'create sample data for testing'
62
+ task populate_template_database: :environment do
63
+ raise 'must be test env' unless Rails.env == 'test'
67
64
  puts "populate test data\n"
68
- load "#{ TEST_SEED_PATH }/seed.rb"
65
+ load "#{TEST_SEED_PATH}/seed.rb"
69
66
  SharedData.add_test_data
70
67
  end
71
-
72
68
  end
@@ -1,7 +1,7 @@
1
1
  require 'wagn/application'
2
2
 
3
- WAGN_SEED_TABLES = %w{ cards card_actions card_acts card_changes
4
- card_references }
3
+ WAGN_SEED_TABLES = %w( cards card_actions card_acts card_changes
4
+ card_references ).freeze
5
5
  WAGN_SEED_PATH = File.join(
6
6
  ENV['DECKO_SEED_REPO_PATH'] || [Cardio.gem_root, 'db', 'seed'], 'new'
7
7
  )
@@ -86,7 +86,7 @@ namespace :wagn do
86
86
  end
87
87
  Dir.mkdir Wagn.paths['tmp'].first
88
88
  Rake::Task['wagn:migrate'].invoke
89
- # FIXME remove tmp dir / clear cache
89
+ # FIXME: remove tmp dir / clear cache
90
90
  puts 'set symlink for assets'
91
91
  Rake::Task['wagn:update_assets_symlink'].invoke
92
92
  end
@@ -99,7 +99,7 @@ namespace :wagn do
99
99
  desc 'set symlink for assets'
100
100
  task :update_assets_symlink do
101
101
  assets_path = File.join(Rails.public_path, 'assets')
102
- if Rails.root.to_s != Wagn.gem_root and not File.exists? assets_path
102
+ if Rails.root.to_s != Wagn.gem_root && !File.exist?(assets_path)
103
103
  FileUtils.rm assets_path if File.symlink? assets_path
104
104
  FileUtils.ln_s(Decko::Engine.paths['gem-assets'].first, assets_path)
105
105
  end
@@ -114,21 +114,20 @@ namespace :wagn do
114
114
 
115
115
  puts 'migrating structure'
116
116
  Rake::Task['wagn:migrate:structure'].invoke
117
- if stamp
118
- Rake::Task['wagn:migrate:stamp'].invoke :structure
119
- end
117
+ Rake::Task['wagn:migrate:stamp'].invoke :structure if stamp
120
118
 
121
119
  puts 'migrating core cards'
122
120
  Card::Cache.reset_all
123
- Rake::Task['wagn:migrate:core_cards'].execute #not invoke because we don't want to reload environment
121
+ # not invoke because we don't want to reload environment
122
+ Rake::Task['wagn:migrate:core_cards'].execute
124
123
  if stamp
125
124
  Rake::Task['wagn:migrate:stamp'].reenable
126
125
  Rake::Task['wagn:migrate:stamp'].invoke :core_cards
127
126
  end
128
127
 
129
-
130
128
  puts 'migrating deck cards'
131
- Rake::Task['wagn:migrate:deck_cards'].execute #not invoke because we don't want to reload environment
129
+ # not invoke because we don't want to reload environment
130
+ Rake::Task['wagn:migrate:deck_cards'].execute
132
131
  if stamp
133
132
  Rake::Task['wagn:migrate:stamp'].reenable
134
133
  Rake::Task['wagn:migrate:stamp'].invoke :deck_cards
@@ -194,9 +193,9 @@ namespace :wagn do
194
193
  end
195
194
  end
196
195
 
197
- # maybe we should move this to a method?
196
+ # maybe we should move this to a method?
198
197
  desc 'write the version to a file (not usually called directly)'
199
- task :stamp, :type do |t, args|
198
+ task :stamp, :type do |_t, args|
200
199
  ENV['SCHEMA'] ||= "#{Cardio.gem_root}/db/schema.rb"
201
200
  Cardio.config.action_mailer.perform_deliveries = false
202
201
 
@@ -204,7 +203,7 @@ namespace :wagn do
204
203
 
205
204
  Cardio.schema_mode args[:type] do
206
205
  version = ActiveRecord::Migrator.current_version
207
- if version.to_i > 0 and file = open(stamp_file, 'w')
206
+ if version.to_i > 0 && (file = open(stamp_file, 'w'))
208
207
  puts ">> writing version: #{version} to #{stamp_file}"
209
208
  file.puts version
210
209
  end
@@ -212,33 +211,30 @@ namespace :wagn do
212
211
  end
213
212
  end
214
213
 
215
-
216
214
  namespace :emergency do
217
215
  task rescue_watchers: :environment do
218
216
  follower_hash = Hash.new { |h, v| h[v] = [] }
219
217
 
220
218
  Card.where('right_id' => 219).each do |watcher_list|
221
219
  watcher_list.include_set_modules
222
- if watcher_list.left
223
- watching = watcher_list.left.name
224
- watcher_list.item_names.each do |user|
225
- follower_hash[user] << watching
226
- end
220
+ next unless watcher_list.left
221
+ watching = watcher_list.left.name
222
+ watcher_list.item_names.each do |user|
223
+ follower_hash[user] << watching
227
224
  end
228
225
  end
229
226
 
230
- Card.search(right: {codename: 'following'}).each do |following|
227
+ Card.search(right: { codename: 'following' }).each do |following|
231
228
  Card::Auth.as_bot do
232
229
  following.update_attributes! content: ''
233
230
  end
234
231
  end
235
232
 
236
233
  follower_hash.each do |user, items|
237
- if card=Card.fetch(user) and card.account
238
- Card::Auth.as(user) do
239
- following = card.fetch trait: 'following', new: {}
240
- following.items = items
241
- end
234
+ next unless (card = Card.fetch(user)) && card.account
235
+ Card::Auth.as(user) do
236
+ following = card.fetch trait: 'following', new: {}
237
+ following.items = items
242
238
  end
243
239
  end
244
240
  end
@@ -259,14 +255,12 @@ namespace :wagn do
259
255
  task dump: :environment do
260
256
  Card::Cache.reset_all
261
257
 
262
- # FIXME temporarily taking this out!!
258
+ # FIXME: temporarily taking this out!!
263
259
  Rake::Task['wagn:bootstrap:copy_mod_files'].invoke
264
260
 
265
- if RUBY_VERSION !~ /^(2|1\.9)/
266
- YAML::ENGINE.yamler = 'syck'
267
- end
268
- # use old engine while we're supporting ruby 1.8.7 because it can't support Psych,
269
- # which dumps with slashes that syck can't understand
261
+ YAML::ENGINE.yamler = 'syck' if RUBY_VERSION !~ /^(2|1\.9)/
262
+ # use old engine while we're supporting ruby 1.8.7 because it can't
263
+ # support Psych, which dumps with slashes that syck can't understand
270
264
 
271
265
  WAGN_SEED_TABLES.each do |table|
272
266
  i = '000'
@@ -274,29 +268,28 @@ namespace :wagn do
274
268
  data = ActiveRecord::Base.connection.select_all(
275
269
  "select * from #{table}"
276
270
  )
277
- file.write YAML::dump( data.inject({}) do |hash, record|
278
- record['trash'] = false if record.has_key? 'trash'
279
- record['draft'] = false if record.has_key? 'draft'
280
- if record.has_key? 'content'
281
- record['content'] = record['content'].gsub /\u00A0/, '&nbsp;'
282
- # sych was handling nonbreaking spaces oddly. would not be needed with psych.
271
+ file.write YAML.dump(data.inject({}) do |hash, record|
272
+ record['trash'] = false if record.key? 'trash'
273
+ record['draft'] = false if record.key? 'draft'
274
+ if record.key? 'content'
275
+ record['content'] = record['content'].gsub(/\u00A0/, '&nbsp;')
276
+ # sych was handling nonbreaking spaces oddly.
277
+ # would not be needed with psych.
283
278
  end
284
279
  hash["#{table}_#{i.succ!}"] = record
285
280
  hash
286
281
  end)
287
282
  end
288
283
  end
289
-
290
284
  end
291
285
 
292
286
  desc 'copy files from template database to standard mod and update cards'
293
287
  task copy_mod_files: :environment do
294
-
295
288
  source_files_dir = "#{Wagn.root}/files"
296
289
 
297
290
  # mark mod files as mod files
298
291
  Card::Auth.as_bot do
299
- Card.search(type: ['in', 'Image', 'File'], ne: '').each do |card|
292
+ Card.search(type: %w(in Image File), ne: '').each do |card|
300
293
  if card.mod_file? || card.codename == 'new_file' ||
301
294
  card.codename == 'new_image'
302
295
  puts "skipping #{card.name}: already in code"
@@ -307,15 +300,21 @@ namespace :wagn do
307
300
 
308
301
  raise 'need codename for file' unless card.codename.present?
309
302
 
310
- files = {original: card.attachment.path}
303
+ files = { original: card.attachment.path }
311
304
  card.attachment.versions.each_key do |version|
312
305
  files[version] = card.attachment.path(version)
313
306
  end
314
307
 
315
308
  # make card a mod file card
316
- mod_name = (l = card.left) && l.type_id==Card::SkinID ? '06_bootstrap' : '05_standard'
317
- card.update_column :db_content, card.attachment.db_content(mod: mod_name)
318
- card.last_action.change_for(2).first.update_column :value, card.attachment.db_content(mod: mod_name)
309
+ mod_name = if (l = card.left) && l.type_id == Card::SkinID
310
+ '06_bootstrap'
311
+ else
312
+ '05_standard'
313
+ end
314
+ card.update_column :db_content,
315
+ card.attachment.db_content(mod: mod_name)
316
+ card.last_action.change_for(2).first
317
+ .update_column :value, card.attachment.db_content(mod: mod_name)
319
318
  card.expire
320
319
  card = Card.fetch card.name
321
320
 
@@ -340,8 +339,8 @@ namespace :wagn do
340
339
  end
341
340
 
342
341
  def correct_time_and_user_stamps
343
- conn = ActiveRecord::Base.connection
344
- who_and_when = [ Card::WagnBotID, Time.now.utc.to_s(:db) ]
342
+ conn = ActiveRecord::Base.connection
343
+ who_and_when = [Card::WagnBotID, Time.now.utc.to_s(:db)]
345
344
  card_sql = "update cards set creator_id=%1$s, created_at='%2$s', updater_id=%1$s, updated_at='%2$s'"
346
345
  conn.update(card_sql % who_and_when)
347
346
  conn.update("update card_acts set actor_id=%s, acted_at='%s'" % who_and_when)
@@ -350,15 +349,13 @@ end
350
349
  def delete_unwanted_cards
351
350
  Card::Auth.as_bot do
352
351
  if ignoramus = Card['*ignore']
353
- ignoramus.item_cards.each do |card|
354
- card.delete!
355
- end
352
+ ignoramus.item_cards.each(&:delete!)
356
353
  end
357
354
  Card::Cache.reset_all
358
355
  # FIXME: can this be associated with the machine module somehow?
359
- %w{ machine_input machine_output }.each do |codename|
360
- Card.search(:right=>{:codename=>codename }).each do |card|
361
- FileUtils.rm_rf File.join('files', card.id.to_s ), :secure=>true
356
+ %w( machine_input machine_output ).each do |codename|
357
+ Card.search(right: { codename: codename }).each do |card|
358
+ FileUtils.rm_rf File.join('files', card.id.to_s), secure: true
362
359
  card.delete!
363
360
  end
364
361
  end
@@ -369,12 +366,12 @@ def clear_history
369
366
  Card::Action.delete_old
370
367
  Card::Change.delete_actionless
371
368
 
372
- conn = ActiveRecord::Base.connection
373
- conn.execute( "truncate card_acts" )
374
- conn.execute( "truncate sessions" )
369
+ conn = ActiveRecord::Base.connection
370
+ conn.execute('truncate card_acts')
371
+ conn.execute('truncate sessions')
375
372
  act = Card::Act.create! actor_id: Card::WagnBotID,
376
- :card_id=>Card::WagnBotID
373
+ card_id: Card::WagnBotID
377
374
  Card::Action.find_each do |action|
378
- action.update_attributes!(:card_act_id=>act.id)
375
+ action.update_attributes!(card_act_id: act.id)
379
376
  end
380
377
  end