This commit is contained in:
z9hang 2015-01-27 16:03:53 +08:00
commit 91a8078cae
3 changed files with 160 additions and 156 deletions

224
Gemfile
View File

@ -1,44 +1,44 @@
source 'http://rubygems.org'
#source 'http://ruby.sdutlinux.org/'
unless RUBY_PLATFORM =~ /w32/
# unix-like only
#source 'http://ruby.sdutlinux.org/'
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
gem 'rubyzip'
gem 'zip-zip'
end
gem 'rubyzip'
gem 'zip-zip'
end
gem 'grape', '~> 0.9.0'
gem 'grape-entity'
gem 'seems_rateable', path: 'lib/seems_rateable'
gem "rails", "3.2.13"
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem 'acts-as-taggable-on', '2.4.1'
gem 'seems_rateable', path: 'lib/seems_rateable'
gem "rails", "3.2.13"
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
#gem 'email_verifier'
group :development do
group :development do
gem 'grape-swagger'
gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git'
#gem 'puma'
gem 'better_errors', path: 'lib/better_errors'
gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler'
end
group :test do
gem "shoulda", "~> 3.5.0"
gem "mocha", "~> 1.1.0"
gem 'capybara', '~> 2.4.1'
gem 'nokogiri', '~> 1.6.3'
gem 'factory_girl', '~> 4.4.0'
gem 'selenium-webdriver', '~> 2.42.0'
gem 'better_errors', path: 'lib/better_errors'
gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler'
end
group :test do
gem "shoulda", "~> 3.5.0"
gem "mocha", "~> 1.1.0"
gem 'capybara', '~> 2.4.1'
gem 'nokogiri', '~> 1.6.3'
gem 'factory_girl', '~> 4.4.0'
gem 'selenium-webdriver', '~> 2.42.0'
gem "faker"
# platforms :mri, :mingw do
# group :rmagick do
# # RMagick 2 supports ruby 1.9
@ -47,86 +47,86 @@ group :test do
# gem "rmagick", ">= 2.0.0"
# end
#end
end
end
gem 'rspec-rails' , '2.13.1'
gem 'guard-rspec','2.5.0'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
# Optional gem for LDAP authentication
group :ldap do
gem "net-ldap", "~> 0.3.1"
end
# Optional gem for OpenID authentication
group :openid do
gem "ruby-openid", "~> 2.1.4", :require => "openid"
gem "rack-openid"
end
# Optional gem for exporting the gantt to a PNG file, not supported with jruby
platforms :jruby do
# jruby-openssl is bundled with JRuby 1.7.0
gem "jruby-openssl" if Object.const_defined?(:JRUBY_VERSION) && JRUBY_VERSION < '1.7.0'
gem "activerecord-jdbc-adapter", "1.2.5"
end
# Include database gems for the adapters found in the database
# configuration file
require 'erb'
require 'yaml'
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
database_config = YAML::load(ERB.new(IO.read(database_file)).result)
adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
if adapters.any?
adapters.each do |adapter|
case adapter
when 'mysql2'
gem "mysql2", "= 0.3.11", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
when 'mysql'
gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
when /postgresql/
gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw]
gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
when /sqlite3/
gem "sqlite3", :platforms => [:mri, :mingw]
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
when /sqlserver/
gem "tiny_tds", "~> 0.5.1", :platforms => [:mri, :mingw]
gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
else
warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
end
end
else
warn("No adapter found in config/database.yml, please configure it first")
end
else
warn("Please configure your config/database.yml first")
end
local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
if File.exists?(local_gemfile)
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(local_gemfile)
end
# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(file)
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
# Optional gem for LDAP authentication
group :ldap do
gem "net-ldap", "~> 0.3.1"
end
# Optional gem for OpenID authentication
group :openid do
gem "ruby-openid", "~> 2.1.4", :require => "openid"
gem "rack-openid"
end
# Optional gem for exporting the gantt to a PNG file, not supported with jruby
platforms :jruby do
# jruby-openssl is bundled with JRuby 1.7.0
gem "jruby-openssl" if Object.const_defined?(:JRUBY_VERSION) && JRUBY_VERSION < '1.7.0'
gem "activerecord-jdbc-adapter", "1.2.5"
end
# Include database gems for the adapters found in the database
# configuration file
require 'erb'
require 'yaml'
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
database_config = YAML::load(ERB.new(IO.read(database_file)).result)
adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
if adapters.any?
adapters.each do |adapter|
case adapter
when 'mysql2'
gem "mysql2", "= 0.3.11", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
when 'mysql'
gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
when /postgresql/
gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw]
gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
when /sqlite3/
gem "sqlite3", :platforms => [:mri, :mingw]
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
when /sqlserver/
gem "tiny_tds", "~> 0.5.1", :platforms => [:mri, :mingw]
gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
else
warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
end
end
else
warn("No adapter found in config/database.yml, please configure it first")
end
else
warn("Please configure your config/database.yml first")
end
local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
if File.exists?(local_gemfile)
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(local_gemfile)
end
# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(file)
end

View File

@ -6,7 +6,7 @@
method: :post do |f| %>
<div class="box tabular">
<%= render :partial => 'form_contest', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create), :style=> "margin-left: 100px;margin-top: 10px;" %>
<%= javascript_tag "$('#bid_name').focus();" %>
<% end %>
</div>

View File

@ -1,23 +1,24 @@
require 'spec_helper'
describe User do
#测试数据验证
# before { @user = User.new(login: "ExampleUser" ,mail: "user@example.com",
# password: "foobar",password_confirmation: "foobar" ) }
# 测试数据验证
# 此处采用预构件的方式生成数据
# it "has a valid facrtory" do
# expect(FactoryGirl.create(:user)).not_to be_valid
# end
before :each do
@user = User.new(login: "ExampleUser" ,mail: "user@example.com",
password: "foobar",password_confirmation: "foobar" )
@user = User.new(login: 'ExampleUser',firstname: 'sanfeng',lastname: 'zhang' ,mail: 'user@example.com',
password: 'foobar',password_confirmation: 'foobar' )
end
subject { @user }#指定@user为测试对象
#属性存在性的测试
# 指定@user为测试对象
subject { @user }
# 属性存在性的测试
it { should respond_to(:login) }
it { should respond_to(:mail) }
#此处采用与构建的方式生成数据
# it"is invalid without login" do
# user=FactoryGirl.build(:user,login: nil)
# expect(user).to_not be_valid
# end
#用户名唯一性的测试
# 用户名唯一性的测试
describe "when login is already taken" do
before do
user_with_same_login=@user.dup
@ -29,11 +30,12 @@ describe User do
# end
end
#邮箱唯一性测试
# 邮箱唯一性测试
describe "when mail address is already taken " do
before do
user_with_same_mail=@user.dup#dup method copy mail
user_with_same_mail.mail=@user.mail.upcase#转大写
#dup method copy mail
user_with_same_mail=@user.dup
user_with_same_mail.mail=@user.mail.upcase
user_with_same_mail.save
end
it{should_not be_valid}
@ -48,10 +50,10 @@ describe User do
#login长度测试(login最大25字符)
describe "when the login is too long " do
before{@user.login='a'*25}
it{should be_valid}
before{@user.login='a'*26}
it{should_not be_valid}
end
#姓和名的长度测试
# 姓和名的长度测试
describe "when the first name is too long " do
before{@user.firstname='a'*30}
it{should_not be_valid}
@ -61,7 +63,7 @@ describe User do
it{should_not be_valid}
end
#login合法性的测试(符合正则表达式规则的用户名:数字英文)
# login合法性的测试(符合正则表达式规则的用户名:数字英文)
describe "when login format is invalid" do
it"should be invalid" do
username=%w[aa!3 aaa%$&*! 1111==!]
@ -82,7 +84,7 @@ describe User do
end
end
#邮箱合法性测试在模型user中邮箱使用了正则表达式
# 邮箱合法性测试在模型user中邮箱使用了正则表达式
describe "is the mail valid" do
context "when mail format is invalid" do
it"should be invalid" do
@ -104,37 +106,39 @@ describe User do
end
end
end
describe "when the mail is too long" do#邮箱长度验证的测试
# 邮箱长度验证的测试
describe "when the mail is too long" do
before{@user.mail='a'*60}
it{should_not be_valid}
end
#验证两次输入的密码是否一致的测试
# 验证两次输入的密码是否一致的测试
describe "when the password does not match confirmation" do
before{@user.password_confirmation="admin123"}
it{should_not be_valid}
end
#调用相关方法是否能返回期待的结果
#userInfo方法选择项目成员时显示的用户信息的文字
describe "returns the user info when choice the members of the project" do
context "第一种情况" do
@user=User.new()
expect(@user.userInfo).to eq ''
end
context "二种情况" do
@user=User.new()
expect(@user.userInfo).to eq ''
end
# 选择项目成员时显示的用户信息文字userInfo方法的测试
# describe "when choice the peoject number show the user info" do
# before{ @userwd = User.new(login: 'wudang',firstname: 'sanfeng',lastname: 'zhang' ,mail: 'user@example.com',
# password: 'foobar',password_confirmation: 'foobar' )}
# it "when the firstname and lastname is nil " do
# expect(@userwd.userInfo).to eq 'wudang (zhang sanfeng)'
# end
#
# end
# 返回用户全名的测试
it "return full user's name" do
expect(@user.show_name).to eq 'zhangsanfeng'
end
# 返回匿名用户方法的测试
# User调用其类方法anonymous,返回一个AnonymousUser的实例对象@anonymoususer
# 该对象的lastname属性被赋值为"Anonymous",最后对比其值是否相等
it "return the anonymous user" do
@anonymoususer=AnonymousUser.new
@anonymoususer=User.anonymous
expect(@anonymoususer.lastname).to eq 'Anonymous'
end
# def name
# [firstname, lastname].join(' ')
# end
# it "returns a contact's full name as a string" do
# contact = Contact.new(firstname: 'John', lastname: 'Doe',
# email: 'johndoe@example.com')
# expect(contact.name).to eq 'John Doe'#调用contact的name方法
# end
end