Sha256: c301677429bd99a57f526e41664d79453104ce8778023c8e49e5dffbfed60400

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

Given /^I setup a new rails app "([^"]*)"$/ do |app|
  run_simple("rails new #{app} -d mysql")
  cd app
end

Given /^I install banyan$/ do
  run_simple("bundle exec rake db:create", true)
  run_simple("rails g banyan", true)
  run_simple("bundle exec rake db:migrate", true)
end

Then /^the file "([^"]*)" should be valid yaml$/ do |file|
  expect do
    in_current_dir do
      YAML::load_file(file)
    end
  end.to_not raise_error
end

Given /^I seed the database with Categories:$/ do |table|
  in_current_dir do
    File.open("db/seeds.rb", 'w+') do |file|
      table.hashes.each do |row|
        file.puts("category = Banyan::Category.create!(tag: #{row['tag'].inspect}, name: #{row['name'].inspect})")
      end
    end
  end

  run_simple("bundle exec rake db:seed", true)
end

Given /^I seed the database with Groups:$/ do |table|
  in_current_dir do
    File.open("db/seeds.rb", 'w+') do |file|
      table.hashes.each do |row|
        file.puts("category_group = Banyan::CategoryGroup.create!(tag: #{row['tag'].inspect}, name: #{row['name'].inspect})")
      end
    end
  end

  run_simple("bundle exec rake db:seed", true)
end

Given /^"a file named "([^"]*)" with:"$/ do |filename, hash|
  in_current_dir do
    File.open(filename, "w") do |f|
      f.puts(yaml(hash))
    end
  end
end

Given /^I translate "([^"]*)" to "([^"]*)" into "([^"]*)"$/ do |path, value, filename|
  in_current_dir do
    categories, language, tag = path.split('.')

    patch_hash = {categories => {language => {tag => value}}}

    ydata = YAML.load_file(filename)

    deep_merge_strategy = lambda do |conflicted_key, receiver_value, argument_value|
      case receiver_value when Hash
        case argument_value when Hash
          receiver_value.merge(argument_value,&deep_merge_strategy)
        else
          argument_value
        end
      else
        argument_value
      end
    end

    ydata.merge!(patch_hash,&deep_merge_strategy)

    File.open(filename, "w") do |f|
      f.puts(ydata.to_yaml)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
banyan-1.1.1 features/step_definitions/translation_import_and_export_steps.rb