Sha256: ee4e63e92df2b2126bb05786e5c5b324ec3c1fa1bfa2e8ced61c6d73f6f76759

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))

require 'rspec'
require 'ledger_web/config'
require 'ledger_web/db'
require 'ledger_web/report'
require 'ledger_web/helpers'
require 'database_cleaner'

RSpec.configure do |config|

  config.before(:suite) do

    system 'createdb ledger-test'
    LedgerWeb::Config.should_load_user_config = false
    LedgerWeb::Config.instance.set :database_url, 'postgres://localhost/ledger-test'
    LedgerWeb::Database.connect
    LedgerWeb::Database.run_migrations
    
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.after(:suite) do
    LedgerWeb::Database.close
    system 'dropdb ledger-test'
  end

end

def set_config(key, val)
  LedgerWeb::Config.instance.set key, val
end

def fixture(name)
  File.join(File.dirname(__FILE__), "fixtures", name + ".dat")
end

def convert_bd_to_string(objs)
  objs.map do |obj|
    obj.each do |k,v|
      if v.is_a? BigDecimal
        obj[k] = v.truncate(2).to_s('F')
      end
    end
    obj
  end
end

def load_fixture(name)
  set_config :ledger_file, fixture(name)
  file = LedgerWeb::Database.dump_ledger_to_csv
  LedgerWeb::Database.load_database(file)
end

def field(name, type, css_class)
  LedgerWeb::Field.new(name, type, css_class)
end

def string_field(name)
  field(name, 'string', 'pull-left')
end

def number_field(name)
  field(name, 'number', 'pull-right')
end

class TestHelper
  include LedgerWeb::Helpers
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ledger_web-1.5.2 test/spec_helper.rb
ledger_web-1.5.1 test/spec_helper.rb
ledger_web-1.5.0 test/spec_helper.rb
ledger_web-1.4.11 test/spec_helper.rb
ledger_web-1.4.10 test/spec_helper.rb
ledger_web-1.4.9 test/spec_helper.rb
ledger_web-1.4.8 test/spec_helper.rb
ledger_web-1.4.7 test/spec_helper.rb
ledger_web-1.4.6 test/spec_helper.rb