Fix test cases
This commit is contained in:
parent
6ec662459f
commit
33b7f6666d
3
Gemfile
3
Gemfile
|
@ -67,7 +67,8 @@ end
|
|||
|
||||
group :test, :development do
|
||||
gem "rspec-rails", ">= 2.8.1"
|
||||
gem 'rails-controller-testing'
|
||||
gem 'pry-rails'
|
||||
gem 'pry-nav'
|
||||
#gem 'factory_girl_rails'
|
||||
gem 'factory_girl_rails'
|
||||
end
|
||||
|
|
11
Gemfile.lock
11
Gemfile.lock
|
@ -86,6 +86,11 @@ GEM
|
|||
unf (>= 0.0.5, < 1.0.0)
|
||||
erubis (2.7.0)
|
||||
execjs (2.6.0)
|
||||
factory_girl (4.7.0)
|
||||
activesupport (>= 3.0.0)
|
||||
factory_girl_rails (4.7.0)
|
||||
factory_girl (~> 4.7.0)
|
||||
railties (>= 3.0.0)
|
||||
ffi (1.9.10)
|
||||
figaro (1.1.1)
|
||||
thor (~> 0.14)
|
||||
|
@ -200,6 +205,10 @@ GEM
|
|||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 5.0.0.beta3)
|
||||
sprockets-rails (>= 2.0.0)
|
||||
rails-controller-testing (0.1.1)
|
||||
actionpack (~> 5.x)
|
||||
actionview (~> 5.x)
|
||||
activesupport (~> 5.x)
|
||||
rails-deprecated_sanitizer (1.0.3)
|
||||
activesupport (>= 4.2.0.alpha)
|
||||
rails-dom-testing (1.0.7)
|
||||
|
@ -331,6 +340,7 @@ DEPENDENCIES
|
|||
codeclimate-test-reporter
|
||||
coffee-rails (~> 4.1.0)
|
||||
database_cleaner
|
||||
factory_girl_rails
|
||||
figaro
|
||||
font-awesome-sass
|
||||
foundation-icons-sass-rails
|
||||
|
@ -359,6 +369,7 @@ DEPENDENCIES
|
|||
quiet_assets
|
||||
rack-cors
|
||||
rails (>= 5.0.0.beta3, < 5.1)
|
||||
rails-controller-testing
|
||||
rails-i18n (~> 5.0.0.beta3)
|
||||
redcarpet
|
||||
redis-namespace
|
||||
|
|
|
@ -13,8 +13,8 @@ WBlog::Application.configure do
|
|||
config.eager_load = false
|
||||
|
||||
# Configure static asset server for tests with Cache-Control for performance.
|
||||
config.serve_static_files = true
|
||||
config.static_cache_control = "public, max-age=3600"
|
||||
config.public_file_server.enabled = true
|
||||
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
|
||||
|
||||
# Show full error reports and disable caching.
|
||||
config.consider_all_requests_local = true
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeColumnDefaultEnableSubscribes < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
change_column_default :subscribes, :enable, true
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160421062614) do
|
||||
ActiveRecord::Schema.define(version: 20160425042136) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -58,9 +58,9 @@ ActiveRecord::Schema.define(version: 20160421062614) do
|
|||
|
||||
create_table "subscribes", force: :cascade do |t|
|
||||
t.string "email"
|
||||
t.boolean "enable"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "enable", default: true
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,48 +2,10 @@ require 'spec_helper'
|
|||
|
||||
describe ArchivesController do
|
||||
|
||||
def posts_data(response)
|
||||
JSON.parse(response.body)["posts"]
|
||||
end
|
||||
|
||||
describe "GET 'index'" do
|
||||
it "json" do
|
||||
get 'index', format: :json
|
||||
expect(posts_data(response).size).to eq(0)
|
||||
end
|
||||
|
||||
it "add ten" do
|
||||
posts = create_list(:post_list, 10)
|
||||
get 'index', format: :json
|
||||
expect(posts_data(response).size).to eq(10)
|
||||
end
|
||||
|
||||
it "add 20" do
|
||||
posts = create_list(:post_list, 20)
|
||||
get 'index', format: :json
|
||||
expect(posts_data(response).size).to eq(10)
|
||||
end
|
||||
|
||||
it "type filter" do
|
||||
posts = create_list(:post_list, 20)
|
||||
life_posts = create_list(:post_list, 5, type: Post::LIFE)
|
||||
get 'index', type: 'life', format: :json
|
||||
expect(posts_data(response).size).to eq(5)
|
||||
end
|
||||
|
||||
it "start_with filter" do
|
||||
posts = create_list(:post_list, 10)
|
||||
start_with = posts[4].created_at.to_i.to_s
|
||||
get 'index', start_with: start_with, format: :json
|
||||
expect(posts_data(response).size).to eq(5)
|
||||
end
|
||||
|
||||
it "load_more" do
|
||||
posts = create_list(:post_list, 20)
|
||||
get 'index', format: :json
|
||||
start_with = JSON.parse(response.body)['start_with']
|
||||
expect(start_with).to eq( posts[9].created_at.to_i.to_s )
|
||||
end
|
||||
it "get index" do
|
||||
create_list(:post_list, 3)
|
||||
get :index
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe BlogsController do
|
|||
first = Post.first
|
||||
first.update(title: 'first')
|
||||
|
||||
second = Post.desc(:created_at)[1]
|
||||
second = Post.order(created_at: :desc)[1]
|
||||
get :index
|
||||
expect(assigns(:newest)).to eq(first)
|
||||
expect(assigns(:recent)[0]).to eq(second)
|
||||
|
@ -28,13 +28,13 @@ describe BlogsController do
|
|||
comment2.save!
|
||||
|
||||
get :show, id: post.id
|
||||
expect(assigns(:comments)[0]).to eq(comment1)
|
||||
expect(assigns(:comments)[1]).to eq(comment2)
|
||||
expect(assigns(:comments)[0]).to eq(comment2)
|
||||
expect(assigns(:comments)[1]).to eq(comment1)
|
||||
end
|
||||
|
||||
it "#prev, #next" do
|
||||
posts = create_list(:post_list, 3)
|
||||
posts = Post.order_by(created_at: 'asc')
|
||||
posts = Post.order(created_at: :asc)
|
||||
selected = posts[1]
|
||||
s_prev = posts[0]
|
||||
s_next = posts[2]
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe LikesController do
|
||||
|
||||
it "get index" do
|
||||
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
|
||||
a = Post.create!(title: 'one', content: '1'*31)
|
||||
get 'index', blog_id: a.id
|
||||
expect(JSON.parse(response.body)['count']).to eq(0)
|
||||
a.likes << Like.new
|
||||
|
@ -13,13 +13,13 @@ describe LikesController do
|
|||
end
|
||||
|
||||
it "post create" do
|
||||
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
|
||||
a = Post.create!(title: 'one', content: '1'*31)
|
||||
post 'create', blog_id: a.id
|
||||
expect(a.likes.size).to eq(1)
|
||||
end
|
||||
|
||||
it "DELETE destroy" do
|
||||
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
|
||||
a = Post.create!(title: 'one', content: '1'*31)
|
||||
like = Like.new
|
||||
a.likes << like
|
||||
a.save!
|
||||
|
|
|
@ -2,13 +2,11 @@ FactoryGirl.define do
|
|||
factory :post do
|
||||
title 'this is a post title'
|
||||
content 'content' * 10
|
||||
type Post::TECH
|
||||
end
|
||||
|
||||
factory :post_list, class: Post do
|
||||
sequence(:title) { |n| "#{n}: post title" }
|
||||
content 'content' * 10
|
||||
sequence(:created_at) { |n| n.days.ago }
|
||||
type Post::TECH
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Comment, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Label, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Like do
|
||||
it "add like" do
|
||||
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
|
||||
a = Post.create!(title: 'one', content: '1'*31)
|
||||
like = Like.new
|
||||
like.post = a
|
||||
expect(like.save).to eq(true)
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Photo, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -23,6 +23,12 @@ RSpec.configure do |config|
|
|||
|
||||
config.mock_with :rspec
|
||||
config.infer_base_class_for_anonymous_controllers = false
|
||||
|
||||
[:controller, :view, :request].each do |type|
|
||||
config.include ::Rails::Controller::Testing::TestProcess, :type => type
|
||||
config.include ::Rails::Controller::Testing::TemplateAssertions, :type => type
|
||||
config.include ::Rails::Controller::Testing::Integration, :type => type
|
||||
end
|
||||
end
|
||||
|
||||
RSpec::Sidekiq.configure do |config|
|
||||
|
|
Loading…
Reference in New Issue