Sha256: b97a2e4777edc700623acf6c2ab4e5971b03283e3aa853c7e20c85a72938e668

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

# -*- coding: utf-8 -*-
require File.join(File.dirname(__FILE__), 'spec_helper')

describe SchemaComments::SchemaComment do

  before(:each) do
    SchemaComments.yaml_path = File.join(File.dirname(__FILE__), 'human_readable_schema_comments.yml')
    FileUtils.rm(SchemaComments.yaml_path, :verbose => true) if File.exist?(SchemaComments.yaml_path)

    (ActiveRecord::Base.connection.tables - IGNORED_TABLES).each do |t|
      ActiveRecord::Base.connection.drop_table(t) rescue nil
    end
    ActiveRecord::Base.connection.initialize_schema_migrations_table
    ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
  end

  it "should export human readable yaml" do
    ActiveRecord::Schema.define(:version => 0) do
      create_table(:person, :comment => '人') do |t|
        t.string :name, :comment => '名前'
      end

      create_table(:addresses, :comment => '住所') do |t|
        t.integer :person_id, :comment => '人'
        t.text :descriptions, :comment => '記述'
      end

      create_table(:emails, :comment => 'メール') do |t|
        t.integer :person_id, :comment => '人'
        t.string :address, :comment => 'アドレス'
      end
    end

    File.read(SchemaComments.yaml_path).split(/$/).map(&:strip).should == %{
---
table_comments:
  addresses: "住所"
  emails: "メール"
  person: "人"
column_comments:
  addresses:
    person_id: "人"
    descriptions: "記述"
  emails:
    person_id: "人"
    address: "アドレス"
  person:
    name: "名前"
}.split(/$/).map(&:strip)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
schema_comments-0.2.0.alpha5 spec/yaml_export_spec.rb
schema_comments-0.2.0.alpha4 spec/yaml_export_spec.rb
schema_comments-0.2.0.alpha3 spec/yaml_export_spec.rb
schema_comments-0.2.0.alpha2 spec/yaml_export_spec.rb
schema_comments-0.2.0.alpha1 spec/yaml_export_spec.rb