forked from hozaka/rails-bestpractices.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ def new | |
else | ||
@post = Post.new | ||
end | ||
@post.build_post_body | ||
end | ||
|
||
def show | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class PostBody < ActiveRecord::Base | ||
include Markdownable | ||
|
||
belongs_to :post | ||
|
||
validates_presence_of :body | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class CreatePostBodies < ActiveRecord::Migration | ||
def self.up | ||
create_table :post_bodies do |t| | ||
t.text :body | ||
t.text :formatted_html | ||
t.integer :post_id | ||
|
||
t.timestamps | ||
end | ||
ActiveRecord::Base.connection.execute("INSERT INTO post_bodies(body, formatted_html, post_id) SELECT body, formatted_html, id FROM posts") | ||
remove_column :posts, :body | ||
remove_column :posts, :formatted_html | ||
end | ||
|
||
def self.down | ||
add_column :posts, :formatted_html, :text | ||
add_column :posts, :body, :text | ||
ActiveRecord::Base.connection.execute("UPDATE posts, post_bodies SET posts.body = post_bodies.body, posts.formatted_html = post_bodies.formatted_html WHERE posts.id = post_bodies.post_id") | ||
drop_table :post_bodies | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Given /^the (\w+) indexes are processed$/ do |model| | ||
model = model.titleize.gsub(/\s/, '').constantize | ||
ThinkingSphinx::Test.index *model.sphinx_index_names | ||
sleep(0.25) | ||
sleep(2.00) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
Factory.define :post_body do |pb| | ||
pb.body "subject\n=======\ntitle\n-----" | ||
end | ||
|
||
Factory.define :code_post_body, :parent => :post_body do |pb| | ||
pb.body "subject\n=======\ntitle\n-----\n def test\n puts 'test'\n end" | ||
end | ||
|
||
Factory.define :post do |p| | ||
p.sequence(:title) {|n| "Post #{n}" } | ||
p.body "subject\n=======\ntitle\n-----" | ||
p.association :user | ||
p.published true | ||
p.association :post_body | ||
end | ||
|
||
Factory.define :code_post, :parent => :post do |p| | ||
p.sequence(:title) {|n| "Code Post #{n}" } | ||
p.body "subject\n=======\ntitle\n-----\n def test\n puts 'test'\n end" | ||
p.association :post_body, :factory => :code_post_body | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe PostBody do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters