Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add spork gem

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

0 comments on commit 71edaa9

Please sign in to comment.
Something went wrong with that request. Please try again.