Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add spork gem

  • Loading branch information...
commit 71edaa96bdb007385761704ddc6d90f17aab33e2 1 parent 12dd171
Roy Chen authored
8 Gemfile
View
@@ -26,11 +26,15 @@ end
gem 'jquery-rails'
gem "rspec-rails", ">= 2.10.1", :group => [:development, :test]
gem "factory_girl_rails", ">= 3.3.0", :group => [:development, :test]
-gem "shoulda-matchers", :group => :test
-gem "capybara", ">= 1.1.2", :group => :test
gem "devise", ">= 2.1.0"
gem "annotate", ">= 2.5.0"
+group :test do
+ gem "spork"
+ gem "capybara", ">= 1.1.2"
+ gem "shoulda-matchers"
+end
+
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
3  Gemfile.lock
View
@@ -67,6 +67,7 @@ GEM
factory_girl (~> 4.0.0)
railties (>= 3.0.0)
ffi (1.1.5)
+ ffi (1.1.5-x86-mingw32)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
@@ -138,6 +139,7 @@ GEM
rubyzip
shoulda-matchers (1.3.0)
activesupport (>= 3.0.0)
+ spork (0.9.2)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
@@ -177,6 +179,7 @@ DEPENDENCIES
rspec-rails (>= 2.10.1)
sass-rails (~> 3.2.3)
shoulda-matchers
+ spork
sqlite3
therubyracer
uglifier (>= 1.0.3)
19 app/controllers/posts_controller.rb
View
@@ -5,5 +5,24 @@ class PostsController < ApplicationController
def new
@post = Post.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render :json => @post }
+ end
+ end
+
+ def create
+ @post = Post.new params[:post]
+
+ respond_to do |format|
+ if @post.save
+ format.html { redirect_to writers_path }
+ format.json
+ else
+ format.html { render "new" }
+ format.json
+ end
+ end
end
end
2  app/models/post.rb
View
@@ -13,7 +13,5 @@
class Post < ActiveRecord::Base
attr_accessible :title, :content
- belongs_to :writer
-
validates :title, :content, :presence => true
end
1  app/models/writer.rb
View
@@ -28,5 +28,4 @@ class Writer < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
- has_many :posts
end
17 app/views/posts/_post.html.erb
View
@@ -0,0 +1,17 @@
+<%= form_for @post, :html => { :class => "form-horizontal" } do |f| %>
+ <legend>Blog Post</legend>
+
+ <div class="row">
+ <%= f.label :title, :class => "span2" %>
+ <%= f.text_field :title, :class=> "span10" %>
+ </div>
+ <div class="row">
+ <%= f.label :content, :class => "span2" %>
+ <%= f.text_area :content, :class => "span10" %>
+ </div>
+
+ <div class="form-actions">
+ <%= f.submit :class => "btn btn-primary" %>
+ <%= f.submit "Save as Draft", :class => "btn btn-success" %>
+ </div>
+<% end %>
18 app/views/posts/new.html.erb
View
@@ -1,23 +1,7 @@
<div class="container admin-container">
<div class="row-fluid">
<div class="span9">
- <%= form_for @post, :html => { :class => "form-horizontal" } do |f| %>
- <legend>Create New Post</legend>
-
- <div class="row">
- <%= f.label :title, :class => "span2" %>
- <%= f.text_field :title, :class=> "span10" %>
- </div>
- <div class="row">
- <%= f.label :content, :class => "span2" %>
- <%= f.text_area :content, :class => "span10" %>
- </div>
-
- <div class="form-actions">
- <%= f.submit "Create Post", :class => "btn btn-primary" %>
- <%= f.submit "Save as Draft", :class => "btn btn-success" %>
- </div>
- <% end %>
+ <%= render @post %>
</div>
<%= render "writers/right_nav" %>
12 spec/controllers/posts_controller_spec.rb
View
@@ -11,4 +11,16 @@
response.should render_template(:new)
end
end
+
+ describe "push the POST button" do
+ before :each do
+ writer = FactoryGirl.create :writer
+ sign_in writer
+ end
+
+ it "params commit should be Save Post" do
+ post :create, p: FactoryGirl.attributes_for(:post)
+
+ end
+ end
end
2  spec/helpers/macross_helper_spec.rb
View
@@ -11,5 +11,5 @@
# end
# end
describe MacrossHelper do
- pending "add some examples to (or delete) #{__FILE__}"
+
end
2  spec/helpers/posts_helper_spec.rb
View
@@ -11,5 +11,5 @@
# end
# end
describe PostsHelper do
- pending "add some examples to (or delete) #{__FILE__}"
+
end
2  spec/helpers/writers_helper_spec.rb
View
@@ -11,5 +11,5 @@
# end
# end
describe WritersHelper do
- pending "add some examples to (or delete) #{__FILE__}"
+
end
2  spec/models/post_spec.rb
View
@@ -17,7 +17,7 @@
FactoryGirl.create(:post).should be_valid
end
- it { should belong_to(:writer) }
+ # it { should belong_to(:writer) }
it { should validate_presence_of(:title) }
2  spec/models/writer_spec.rb
View
@@ -24,5 +24,5 @@
FactoryGirl.create(:writer).should be_valid
end
- it { should have_many(:posts) }
+ #it { should have_many(:posts) }
end
90 spec/spec_helper.rb
View
@@ -1,38 +1,54 @@
-# This file is copied to spec/ when you run 'rails generate rspec:install'
-ENV["RAILS_ENV"] ||= 'test'
-require File.expand_path("../../config/environment", __FILE__)
-require 'rspec/rails'
-require 'rspec/autorun'
-
-# Requires supporting ruby files with custom matchers and macros, etc,
-# in spec/support/ and its subdirectories.
-Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
-
-RSpec.configure do |config|
- # ## Mock Framework
- #
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
- #
- # config.mock_with :mocha
- # config.mock_with :flexmock
- # config.mock_with :rr
-
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
-
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
- # examples within a transaction, remove the following line or assign false
- # instead of true.
- config.use_transactional_fixtures = true
-
- # If true, the base class of anonymous controllers will be inferred
- # automatically. This will be the default behavior in future versions of
- # rspec-rails.
- config.infer_base_class_for_anonymous_controllers = false
-
- # Run specs in random order to surface order dependencies. If you find an
- # order dependency and want to debug it, you can fix the order by providing
- # the seed, which is printed after each run.
- # --seed 1234
- config.order = "random"
+require 'rubygems'
+require 'spork'
+#uncomment the following line to use spork with the debugger
+#require 'spork/ext/ruby-debug'
+
+Spork.prefork do
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
+ ENV["RAILS_ENV"] ||= 'test'
+ require File.expand_path("../../config/environment", __FILE__)
+ require 'rspec/rails'
+ require 'rspec/autorun'
+ require 'capybara/rspec'
+
+ # Requires supporting ruby files with custom matchers and macros, etc,
+ # in spec/support/ and its subdirectories.
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+ RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = "random"
+ end
end
+
+Spork.each_run do
+ # This code will be run each time you run your specs.
+
+end
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.