Sha256: bf13fc753ff2b15861497a847945938cf19d15c0965e56d5b90773e836cf75c3

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

# setting database tables
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
ActiveRecord::Base.establish_connection(
  :adapter => "sqlite3", 
  :database => "#{root}/simpesearch_gem_test.sqlite3"
)

#require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

# drop tables
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'posts'")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'comments'")

# create tables
ActiveRecord::Base.connection.create_table(:posts) do |t|
    t.string :subject
    t.text   :body
end
ActiveRecord::Base.connection.create_table(:comments) do |t|
    t.string :post_id
    t.text   :body
		t.boolean :spam_flag
end

# insert tables
ActiveRecord::Base.connection.execute("INSERT INTO posts (id,subject,body) VALUES (1, 'subject foo','body foo') ")
ActiveRecord::Base.connection.execute("INSERT INTO posts (id,subject,body) VALUES (2, 'subject bar','body bar') ")
ActiveRecord::Base.connection.execute("INSERT INTO posts (id,subject,body) VALUES (3, 'subject fooz','body baz') ")
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (11, 1,'post1 comment foo') ")
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (12, 1,'post1 comment bar') ")
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (21, 2,'post2 comment foo') ")
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (22, 2,'post2 comment bar') ")
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body,spam_flag) VALUES (31, 3,'post3 comment foo', 1) ")
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body,spam_flag) VALUES (32, 3,'post3 comment bar', 0) ")

# models
class Post < ActiveRecord::Base
	has_many :comments
end
class Comment < ActiveRecord::Base
	belongs_to :post
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple-search-0.9.0 test/tables_models.rb