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

View File

@ -6,7 +6,7 @@
method: :post do |f| %> method: :post do |f| %>
<div class="box tabular"> <div class="box tabular">
<%= render :partial => 'form_contest', :locals => { :f => f } %> <%= 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();" %> <%= javascript_tag "$('#bid_name').focus();" %>
<% end %> <% end %>
</div> </div>

View File

@ -1,23 +1,24 @@
require 'spec_helper' require 'spec_helper'
describe User do 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 before :each do
@user = User.new(login: "ExampleUser" ,mail: "user@example.com", @user = User.new(login: 'ExampleUser',firstname: 'sanfeng',lastname: 'zhang' ,mail: 'user@example.com',
password: "foobar",password_confirmation: "foobar" ) password: 'foobar',password_confirmation: 'foobar' )
end end
subject { @user }#指定@user为测试对象
#属性存在性的测试 # 指定@user为测试对象
subject { @user }
# 属性存在性的测试
it { should respond_to(:login) } it { should respond_to(:login) }
it { should respond_to(:mail) } 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 describe "when login is already taken" do
before do before do
user_with_same_login=@user.dup user_with_same_login=@user.dup
@ -29,11 +30,12 @@ describe User do
# end # end
end end
#邮箱唯一性测试 # 邮箱唯一性测试
describe "when mail address is already taken " do describe "when mail address is already taken " do
before do before do
user_with_same_mail=@user.dup#dup method copy mail #dup method copy mail
user_with_same_mail.mail=@user.mail.upcase#转大写 user_with_same_mail=@user.dup
user_with_same_mail.mail=@user.mail.upcase
user_with_same_mail.save user_with_same_mail.save
end end
it{should_not be_valid} it{should_not be_valid}
@ -48,10 +50,10 @@ describe User do
#login长度测试(login最大25字符) #login长度测试(login最大25字符)
describe "when the login is too long " do describe "when the login is too long " do
before{@user.login='a'*25} before{@user.login='a'*26}
it{should be_valid} it{should_not be_valid}
end end
#姓和名的长度测试 # 姓和名的长度测试
describe "when the first name is too long " do describe "when the first name is too long " do
before{@user.firstname='a'*30} before{@user.firstname='a'*30}
it{should_not be_valid} it{should_not be_valid}
@ -61,7 +63,7 @@ describe User do
it{should_not be_valid} it{should_not be_valid}
end end
#login合法性的测试(符合正则表达式规则的用户名:数字英文) # login合法性的测试(符合正则表达式规则的用户名:数字英文)
describe "when login format is invalid" do describe "when login format is invalid" do
it"should be invalid" do it"should be invalid" do
username=%w[aa!3 aaa%$&*! 1111==!] username=%w[aa!3 aaa%$&*! 1111==!]
@ -82,7 +84,7 @@ describe User do
end end
end end
#邮箱合法性测试在模型user中邮箱使用了正则表达式 # 邮箱合法性测试在模型user中邮箱使用了正则表达式
describe "is the mail valid" do describe "is the mail valid" do
context "when mail format is invalid" do context "when mail format is invalid" do
it"should be invalid" do it"should be invalid" do
@ -104,37 +106,39 @@ describe User do
end end
end end
end end
# 邮箱长度验证的测试
describe "when the mail is too long" do#邮箱长度验证的测试 describe "when the mail is too long" do
before{@user.mail='a'*60} before{@user.mail='a'*60}
it{should_not be_valid} it{should_not be_valid}
end end
#验证两次输入的密码是否一致的测试 # 验证两次输入的密码是否一致的测试
describe "when the password does not match confirmation" do describe "when the password does not match confirmation" do
before{@user.password_confirmation="admin123"} before{@user.password_confirmation="admin123"}
it{should_not be_valid} it{should_not be_valid}
end end
#调用相关方法是否能返回期待的结果 # 选择项目成员时显示的用户信息文字userInfo方法的测试
#userInfo方法选择项目成员时显示的用户信息的文字 # describe "when choice the peoject number show the user info" do
describe "returns the user info when choice the members of the project" do # before{ @userwd = User.new(login: 'wudang',firstname: 'sanfeng',lastname: 'zhang' ,mail: 'user@example.com',
context "第一种情况" do # password: 'foobar',password_confirmation: 'foobar' )}
@user=User.new() # it "when the firstname and lastname is nil " do
expect(@user.userInfo).to eq '' # expect(@userwd.userInfo).to eq 'wudang (zhang sanfeng)'
end # end
context "二种情况" do #
@user=User.new() # end
expect(@user.userInfo).to eq '' # 返回用户全名的测试
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 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 end