test/tables_models.rb in simple-search-0.9.0 vs test/tables_models.rb in simple-search-0.10.0
- old
+ new
@@ -8,10 +8,11 @@
#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'")
+ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'post_likes'")
# create tables
ActiveRecord::Base.connection.create_table(:posts) do |t|
t.string :subject
t.text :body
@@ -19,11 +20,28 @@
ActiveRecord::Base.connection.create_table(:comments) do |t|
t.string :post_id
t.text :body
t.boolean :spam_flag
end
+ActiveRecord::Base.connection.create_table(:post_likes) do |t|
+ t.string :post_id
+ t.boolean :like
+end
+# models
+class Post < ActiveRecord::Base
+ has_many :comments
+ has_many :post_likes
+end
+class Comment < ActiveRecord::Base
+ belongs_to :post
+ has_many :votes
+end
+class PostLike < ActiveRecord::Base
+ belongs_to :post
+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') ")
@@ -31,12 +49,12 @@
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
+Post.all.each do |post|
+ for n in 1..100
+ post_like = PostLike.new(:post => post, :like=> rand(2))
+ post_like.save
+ end
end
-class Comment < ActiveRecord::Base
- belongs_to :post
-end
+