增加后台管理,并将mongoid切回2.x版本, 因为rspec过不了

This commit is contained in:
yafei Lee 2012-06-23 12:07:24 +08:00
parent 3ccd40c93b
commit 51248c60ff
9 changed files with 69 additions and 130 deletions

25
Gemfile
View File

@ -22,29 +22,20 @@ group :assets do
end end
group :test do group :test do
gem 'capybara' #gem 'capybara'
gem 'cucumber-rails' #gem 'cucumber-rails'
gem 'factory_girl' #gem 'factory_girl'
gem 'mongoid-rspec', :require => false #gem 'mongoid-rspec', :require => false
end end
group :test, :development do group :test, :development do
gem 'rspec-rails' gem "rspec-rails", ">= 2.8.1"
end end
gem 'jquery-rails' gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano' # gem 'capistrano'
# To use debugger gem "bluecloth"
# gem 'debugger' gem "simple_form"
gem 'database_cleaner'

View File

@ -28,21 +28,12 @@ GEM
activesupport (3.2.6) activesupport (3.2.6)
i18n (~> 0.6) i18n (~> 0.6)
multi_json (~> 1.0) multi_json (~> 1.0)
addressable (2.2.8)
arel (3.0.2) arel (3.0.2)
bluecloth (2.2.0)
bson (1.6.4) bson (1.6.4)
bson_ext (1.6.4) bson_ext (1.6.4)
bson (~> 1.6.4) bson (~> 1.6.4)
builder (3.0.0) builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.3.2)
ffi (~> 1.0.6)
coffee-rails (3.2.2) coffee-rails (3.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (~> 3.2.0) railties (~> 3.2.0)
@ -50,24 +41,11 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.3.3) coffee-script-source (1.3.3)
cucumber (1.2.1) database_cleaner (0.8.0)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.11.0)
json (>= 1.4.6)
cucumber-rails (1.3.0)
capybara (>= 1.1.2)
cucumber (>= 1.1.8)
nokogiri (>= 1.5.0)
diff-lcs (1.1.3) diff-lcs (1.1.3)
erubis (2.7.0) erubis (2.7.0)
execjs (1.4.0) execjs (1.4.0)
multi_json (~> 1.0) multi_json (~> 1.0)
factory_girl (3.5.0)
activesupport (>= 3.0.0)
ffi (1.0.11)
gherkin (2.11.0)
json (>= 1.4.6)
hike (1.2.1) hike (1.2.1)
i18n (0.6.0) i18n (0.6.0)
journey (1.0.4) journey (1.0.4)
@ -75,26 +53,18 @@ GEM
railties (>= 3.2.0, < 5.0) railties (>= 3.2.0, < 5.0)
thor (~> 0.14) thor (~> 0.14)
json (1.7.3) json (1.7.3)
libwebsocket (0.1.3)
addressable
mail (2.4.4) mail (2.4.4)
i18n (>= 0.4.0) i18n (>= 0.4.0)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
mime-types (1.19) mime-types (1.19)
mongoid (3.0.0.rc) mongo (1.6.2)
bson (~> 1.6.2)
mongoid (2.4.11)
activemodel (~> 3.1) activemodel (~> 3.1)
moped (~> 1.0.0.rc) mongo (<= 1.6.2)
origin (~> 1.0.0.rc)
tzinfo (~> 0.3.22) tzinfo (~> 0.3.22)
mongoid-rspec (1.4.6)
mongoid (>= 3.0.0.rc)
rake
rspec (>= 2.9)
moped (1.0.0.rc)
multi_json (1.3.6) multi_json (1.3.6)
nokogiri (1.5.4)
origin (1.0.1)
polyglot (0.3.3) polyglot (0.3.3)
rack (1.4.1) rack (1.4.1)
rack-cache (1.2) rack-cache (1.2)
@ -134,17 +104,14 @@ GEM
activesupport (>= 3.0) activesupport (>= 3.0)
railties (>= 3.0) railties (>= 3.0)
rspec (~> 2.10.0) rspec (~> 2.10.0)
rubyzip (0.9.9)
sass (3.1.19) sass (3.1.19)
sass-rails (3.2.5) sass-rails (3.2.5)
railties (~> 3.2.0) railties (~> 3.2.0)
sass (>= 3.1.10) sass (>= 3.1.10)
tilt (~> 1.3) tilt (~> 1.3)
selenium-webdriver (2.24.0) simple_form (2.0.2)
childprocess (>= 0.2.5) actionpack (~> 3.0)
libwebsocket (~> 0.1.3) activemodel (~> 3.0)
multi_json (~> 1.0)
rubyzip
sprockets (2.1.3) sprockets (2.1.3)
hike (~> 1.2) hike (~> 1.2)
rack (~> 1.0) rack (~> 1.0)
@ -158,22 +125,19 @@ GEM
uglifier (1.2.5) uglifier (1.2.5)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (~> 1.3) multi_json (~> 1.3)
xpath (0.1.4)
nokogiri (~> 1.3)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
bluecloth
bson_ext bson_ext
capybara
coffee-rails (~> 3.2.1) coffee-rails (~> 3.2.1)
cucumber-rails database_cleaner
factory_girl
jquery-rails jquery-rails
mongoid mongoid
mongoid-rspec
rails (= 3.2.6) rails (= 3.2.6)
rspec-rails rspec-rails (>= 2.8.1)
sass-rails (~> 3.2.3) sass-rails (~> 3.2.3)
simple_form
uglifier (>= 1.0.3) uglifier (>= 1.0.3)

View File

@ -4,5 +4,6 @@ class BlogsController < ApplicationController
end end
def show def show
@post = Post.find(params[:id])
end end
end end

View File

@ -1,5 +1,14 @@
# encoding : utf-8
class Post class Post
TECH = "技术"
LIFE = "生活"
CREATOR = "创业"
include Mongoid::Document include Mongoid::Document
field :title, :type => String field :title, :type => String
field :content, :type => String field :content, :type => String
field :type, :type=> String
validates :title, :presence=>true, :uniqueness=> true
validates :content, :presence=>true, :length => { :minimum=> 30 }
validates :type, :presence=>true, :inclusion => { :in => [ TECH, LIFE, CREATOR ] }
end end

View File

@ -1,2 +1,4 @@
<h1>Blogs#show</h1> <div class="blog">
<p>Find me in app/views/blogs/show.html.erb</p> <h2><%= @post.title %></h2>
<div class="content"><%= @post.content %></div>
</div>

View File

@ -1,60 +1,20 @@
development: development:
# Configure available database sessions. (required) host: localhost
sessions: database: w_blog_development
# Defines the default session. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: w_blog_development
# Provides the hosts the default session can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- localhost:27017
options:
# Change whether the session persists in safe mode by default.
# (default: false)
# safe: false
# Change the default consistency model to :eventual or :strong. test:
# :eventual will send reads to secondaries, :strong sends everything host: localhost
# to master. (default: :eventual) database: w_blog_test
consistency: :strong
# Configure Mongoid specific options. (optional)
options:
# Configuration for whether or not to allow access to fields that do
# not have a field definition on the model. (default: true)
# allow_dynamic_fields: true
# Enable the identity map, needed for eager loading. (default: false) # set these environment variables on your prod server
# identity_map_enabled: false production:
host: <%= ENV['MONGOID_HOST'] %>
# Includes the root model name in json serialization. (default: false) port: <%= ENV['MONGOID_PORT'] %>
# include_root_in_json: false username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
# Include the _type field in serializaion. (default: false) database: <%= ENV['MONGOID_DATABASE'] %>
# include_type_for_serialization: false # slaves:
# - host: slave1.local
# Preload all models in development, needed when models use # port: 27018
# inheritance. (default: false) # - host: slave2.local
# preload_models: false # port: 27019
# Protect id and type from mass assignment. (default: true)
# protect_sensitive_fields: true
# Raise an error when performing a #find and the document is not found.
# (default: true)
# raise_not_found_error: true
# Raise an error when defining a scope with the same name as an
# existing method. (default: false)
# scope_overwrite_exception: false
# Skip the database version check, used when connecting to a db without
# admin access. (default: false)
# skip_version_check: false
# User Active Support's time zone in conversions. (default: true)
# use_activesupport_time_zone: true
# Ensure all times are UTC in the app side. (default: false)
# use_utc: false

View File

@ -1,4 +1,7 @@
WBlog::Application.routes.draw do WBlog::Application.routes.draw do
root :to => 'blogs#index' root :to => 'blogs#index'
resources :blogs, :only=>[:index, :show] resources :blogs, :only=>[:index, :show]
namespace :admin do
resources :posts
end
end end

View File

@ -1,5 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Post do describe Post do
pending "add some examples to (or delete) #{__FILE__}" it "validates should be ok" do
a = Post.create!(title: 'one', content: '1'*31, type: Post::TECH )
a.save.should == true
end
end end

View File

@ -13,15 +13,21 @@ RSpec.configure do |config|
# #
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
# clear test data # clear test data
config.after :suite do
Mongoid.master.collections.select do |collection| config.before :each do
collection.name !~ /system/ DatabaseCleaner.strategy = :truncation
end.each(&:drop) DatabaseCleaner.start
end end
config.after do
DatabaseCleaner.clean
end
# #
# config.mock_with :mocha # config.mock_with :mocha
# config.mock_with :flexmock # config.mock_with :flexmock
# config.mock_with :rr # config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
#config.fixture_path = "#{::Rails.root}/spec/fixtures" #config.fixture_path = "#{::Rails.root}/spec/fixtures"