| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
269449041b | poll测试修改 | 11 years ago |
|
|
8c7016c90e | Poll测试的修改 | 11 years ago |
|
|
a32bea8529 | 删除enterprises_controller_spec.rb | 11 years ago |
|
|
a87baada35 | 调式poll update动作测试 | 11 years ago |
|
|
f91336f985 | poll预构件添加 | 11 years ago |
|
|
757fc27b3f | 问卷预构件修改 | 11 years ago |
|
|
0f03efd404 | 问卷功能测试修改 | 11 years ago |
|
|
98090d0461 | polls_controller的index测试 | 11 years ago |
|
|
94190acd2e | poll预构件添加polls_description属性 | 11 years ago |
|
|
c26df34b74 | 修改poll测试 | 11 years ago |
|
|
2e21b10917 |
Merge branch 'szzh' into zh
Conflicts: Gemfile.lock app/api/mobile/api.rb db/schema.rb |
11 years ago |
|
|
a239cce03d | 问卷预构件添加 | 11 years ago |
|
|
0501d21570 | 修改poll功能测试代码 | 11 years ago |
|
|
ac001a4ba0 | poll功能测试 | 11 years ago |
|
|
7cdcf96845 |
修改问卷
功能测试 |
11 years ago |
|
|
c3e209a253 | 问卷功能测试 | 11 years ago |
|
|
ac3ae45b7b | 冲突解决 | 11 years ago |
|
|
5fbdc70bf8 | rake | 11 years ago |
|
|
53425fb2ef | 添加rspec包 | 11 years ago |
|
|
6e7fcc47d6 | Merge remote-tracking branch 'remotes/origin/szzh' into zh | 11 years ago |
|
|
81e61343e6 |
Merge branch 'szzh' into zh
Conflicts: Gemfile config/application.rb db/schema.rb |
11 years ago |
|
|
c60db498de | rspec测试预制件factory girl gem包安装 | 11 years ago |
|
|
6f95ecc0ab | 测试留言代码 | 11 years ago |
| @@ -30,15 +30,21 @@ group :development do | |||||
| gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler' | gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler' | ||||
| end | end | ||||
| group :development, :test do | |||||
| gem 'rspec-rails' , '2.13.1' | |||||
| gem "factory_girl_rails", "~> 4.2.1" | |||||
| end | |||||
| group :test do | group :test do | ||||
| gem "faker","~> 1.1.2" | |||||
| 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" | |||||
| #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 | ||||
| @@ -49,8 +55,8 @@ group :test do | |||||
| #end | #end | ||||
| end | end | ||||
| gem 'rspec-rails' , '2.13.1' | |||||
| gem 'guard-rspec','2.5.0' | |||||
| # gem 'rspec-rails' , '2.13.1' | |||||
| #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 | ||||
| @@ -70,8 +70,6 @@ GEM | |||||
| rack (>= 1.0.0) | rack (>= 1.0.0) | ||||
| rack-test (>= 0.5.4) | rack-test (>= 0.5.4) | ||||
| xpath (~> 2.0) | xpath (~> 2.0) | ||||
| celluloid (0.16.0) | |||||
| timers (~> 4.0.0) | |||||
| childprocess (0.5.3) | childprocess (0.5.3) | ||||
| ffi (~> 1.0, >= 1.0.11) | ffi (~> 1.0, >= 1.0.11) | ||||
| climate_control (0.0.3) | climate_control (0.0.3) | ||||
| @@ -94,14 +92,16 @@ GEM | |||||
| equalizer (0.0.9) | equalizer (0.0.9) | ||||
| erubis (2.7.0) | erubis (2.7.0) | ||||
| execjs (2.2.1) | execjs (2.2.1) | ||||
| factory_girl (4.4.0) | |||||
| factory_girl (4.2.0) | |||||
| activesupport (>= 3.0.0) | activesupport (>= 3.0.0) | ||||
| faker (1.4.3) | |||||
| factory_girl_rails (4.2.1) | |||||
| factory_girl (~> 4.2.0) | |||||
| railties (>= 3.0.0) | |||||
| faker (1.1.2) | |||||
| i18n (~> 0.5) | i18n (~> 0.5) | ||||
| fastercsv (1.5.5) | fastercsv (1.5.5) | ||||
| ffi (1.9.3) | ffi (1.9.3) | ||||
| ffi (1.9.3-x86-mingw32) | ffi (1.9.3-x86-mingw32) | ||||
| formatador (0.2.5) | |||||
| grape (0.9.0) | grape (0.9.0) | ||||
| activesupport | activesupport | ||||
| builder | builder | ||||
| @@ -118,22 +118,8 @@ GEM | |||||
| grape-swagger (0.8.0) | grape-swagger (0.8.0) | ||||
| grape | grape | ||||
| grape-entity | grape-entity | ||||
| guard (2.11.1) | |||||
| formatador (>= 0.2.4) | |||||
| listen (~> 2.7) | |||||
| lumberjack (~> 1.0) | |||||
| nenv (~> 0.1) | |||||
| notiffany (~> 0.0) | |||||
| pry (>= 0.9.12) | |||||
| shellany (~> 0.0) | |||||
| thor (>= 0.18.1) | |||||
| guard-rspec (2.5.0) | |||||
| guard (>= 1.1) | |||||
| rspec (~> 2.11) | |||||
| hashie (3.3.1) | hashie (3.3.1) | ||||
| hike (1.2.3) | hike (1.2.3) | ||||
| hitimes (1.2.2) | |||||
| hitimes (1.2.2-x86-mingw32) | |||||
| htmlentities (4.3.2) | htmlentities (4.3.2) | ||||
| i18n (0.6.1) | i18n (0.6.1) | ||||
| ice_nine (0.11.0) | ice_nine (0.11.0) | ||||
| @@ -146,16 +132,10 @@ GEM | |||||
| actionpack (>= 3.0.0) | actionpack (>= 3.0.0) | ||||
| activesupport (>= 3.0.0) | activesupport (>= 3.0.0) | ||||
| libv8 (3.16.14.3) | libv8 (3.16.14.3) | ||||
| listen (2.8.5) | |||||
| celluloid (>= 0.15.2) | |||||
| rb-fsevent (>= 0.9.3) | |||||
| rb-inotify (>= 0.9) | |||||
| lumberjack (1.0.9) | |||||
| mail (2.5.4) | mail (2.5.4) | ||||
| mime-types (~> 1.16) | mime-types (~> 1.16) | ||||
| treetop (~> 1.4.8) | treetop (~> 1.4.8) | ||||
| metaclass (0.0.4) | metaclass (0.0.4) | ||||
| method_source (0.8.2) | |||||
| mime-types (1.25.1) | mime-types (1.25.1) | ||||
| mini_portile (0.6.0) | mini_portile (0.6.0) | ||||
| mocha (1.1.0) | mocha (1.1.0) | ||||
| @@ -164,30 +144,17 @@ GEM | |||||
| multi_xml (0.5.5) | multi_xml (0.5.5) | ||||
| mysql2 (0.3.11) | mysql2 (0.3.11) | ||||
| mysql2 (0.3.11-x86-mingw32) | mysql2 (0.3.11-x86-mingw32) | ||||
| nenv (0.2.0) | |||||
| net-ldap (0.3.1) | net-ldap (0.3.1) | ||||
| nokogiri (1.6.3) | nokogiri (1.6.3) | ||||
| mini_portile (= 0.6.0) | mini_portile (= 0.6.0) | ||||
| nokogiri (1.6.3-x86-mingw32) | nokogiri (1.6.3-x86-mingw32) | ||||
| mini_portile (= 0.6.0) | mini_portile (= 0.6.0) | ||||
| notiffany (0.0.3) | |||||
| nenv (~> 0.1) | |||||
| shellany (~> 0.0) | |||||
| paperclip (3.5.4) | paperclip (3.5.4) | ||||
| activemodel (>= 3.0.0) | activemodel (>= 3.0.0) | ||||
| activesupport (>= 3.0.0) | activesupport (>= 3.0.0) | ||||
| cocaine (~> 0.5.3) | cocaine (~> 0.5.3) | ||||
| mime-types | mime-types | ||||
| polyglot (0.3.5) | polyglot (0.3.5) | ||||
| pry (0.9.12.6) | |||||
| coderay (~> 1.0) | |||||
| method_source (~> 0.8) | |||||
| slop (~> 3.4) | |||||
| pry (0.9.12.6-x86-mingw32) | |||||
| coderay (~> 1.0) | |||||
| method_source (~> 0.8) | |||||
| slop (~> 3.4) | |||||
| win32console (~> 1.3) | |||||
| rack (1.4.5) | rack (1.4.5) | ||||
| rack-accept (0.4.5) | rack-accept (0.4.5) | ||||
| rack (>= 0.4) | rack (>= 0.4) | ||||
| @@ -220,9 +187,6 @@ GEM | |||||
| rdoc (~> 3.4) | rdoc (~> 3.4) | ||||
| thor (>= 0.14.6, < 2.0) | thor (>= 0.14.6, < 2.0) | ||||
| rake (10.3.2) | rake (10.3.2) | ||||
| rb-fsevent (0.9.4) | |||||
| rb-inotify (0.9.5) | |||||
| ffi (>= 0.5.0) | |||||
| rdoc (3.12.2) | rdoc (3.12.2) | ||||
| json (~> 1.4) | json (~> 1.4) | ||||
| ref (1.0.5) | ref (1.0.5) | ||||
| @@ -234,10 +198,6 @@ GEM | |||||
| rack-raw-upload | rack-raw-upload | ||||
| rails (>= 3.2.0) | rails (>= 3.2.0) | ||||
| sass-rails | sass-rails | ||||
| rspec (2.13.0) | |||||
| rspec-core (~> 2.13.0) | |||||
| rspec-expectations (~> 2.13.0) | |||||
| rspec-mocks (~> 2.13.0) | |||||
| rspec-core (2.13.1) | rspec-core (2.13.1) | ||||
| rspec-expectations (2.13.0) | rspec-expectations (2.13.0) | ||||
| diff-lcs (>= 1.1.3, < 2.0) | diff-lcs (>= 1.1.3, < 2.0) | ||||
| @@ -262,14 +222,12 @@ GEM | |||||
| multi_json (~> 1.0) | multi_json (~> 1.0) | ||||
| rubyzip (~> 1.0) | rubyzip (~> 1.0) | ||||
| websocket (~> 1.0.4) | websocket (~> 1.0.4) | ||||
| shellany (0.0.1) | |||||
| shoulda (3.5.0) | shoulda (3.5.0) | ||||
| shoulda-context (~> 1.0, >= 1.0.1) | shoulda-context (~> 1.0, >= 1.0.1) | ||||
| shoulda-matchers (>= 1.4.1, < 3.0) | shoulda-matchers (>= 1.4.1, < 3.0) | ||||
| shoulda-context (1.2.1) | shoulda-context (1.2.1) | ||||
| shoulda-matchers (2.6.1) | shoulda-matchers (2.6.1) | ||||
| activesupport (>= 3.0.0) | activesupport (>= 3.0.0) | ||||
| slop (3.6.0) | |||||
| spreadsheet (1.0.0) | spreadsheet (1.0.0) | ||||
| ruby-ole (>= 1.0) | ruby-ole (>= 1.0) | ||||
| sprockets (2.2.2) | sprockets (2.2.2) | ||||
| @@ -283,8 +241,6 @@ GEM | |||||
| thor (0.19.1) | thor (0.19.1) | ||||
| thread_safe (0.3.4) | thread_safe (0.3.4) | ||||
| tilt (1.4.1) | tilt (1.4.1) | ||||
| timers (4.0.1) | |||||
| hitimes | |||||
| treetop (1.4.15) | treetop (1.4.15) | ||||
| polyglot | polyglot | ||||
| polyglot (>= 0.3.1) | polyglot (>= 0.3.1) | ||||
| @@ -298,7 +254,6 @@ GEM | |||||
| descendants_tracker (~> 0.0, >= 0.0.3) | descendants_tracker (~> 0.0, >= 0.0.3) | ||||
| equalizer (~> 0.0, >= 0.0.9) | equalizer (~> 0.0, >= 0.0.9) | ||||
| websocket (1.0.7) | websocket (1.0.7) | ||||
| win32console (1.3.2-x86-mingw32) | |||||
| xpath (2.0.0) | xpath (2.0.0) | ||||
| nokogiri (~> 1.3) | nokogiri (~> 1.3) | ||||
| @@ -315,14 +270,13 @@ DEPENDENCIES | |||||
| capybara (~> 2.4.1) | capybara (~> 2.4.1) | ||||
| coderay (~> 1.0.6) | coderay (~> 1.0.6) | ||||
| coffee-rails (~> 3.2.1) | coffee-rails (~> 3.2.1) | ||||
| factory_girl (~> 4.4.0) | |||||
| faker | |||||
| factory_girl_rails (~> 4.2.1) | |||||
| faker (~> 1.1.2) | |||||
| fastercsv (~> 1.5.0) | fastercsv (~> 1.5.0) | ||||
| grape (~> 0.9.0) | grape (~> 0.9.0) | ||||
| grape-entity | grape-entity | ||||
| grape-swagger | grape-swagger | ||||
| grape-swagger-ui! | grape-swagger-ui! | ||||
| guard-rspec (= 2.5.0) | |||||
| htmlentities | htmlentities | ||||
| i18n (~> 0.6.0) | i18n (~> 0.6.0) | ||||
| jquery-rails (~> 2.0.2) | jquery-rails (~> 2.0.2) | ||||
| @@ -1,11 +1,5 @@ | |||||
| module Mobile | module Mobile | ||||
| require_relative 'middleware/error_handler' | |||||
| require_relative 'apis/auth' | |||||
| require_relative 'apis/users' | |||||
| require_relative 'apis/courses' | |||||
| require_relative 'apis/watches' | |||||
| require_relative 'apis/upgrade' | |||||
| require_relative 'apis/homeworks' | |||||
| class API < Grape::API | class API < Grape::API | ||||
| version 'v1', using: :path | version 'v1', using: :path | ||||
| format :json | format :json | ||||
| @@ -39,7 +33,7 @@ module Mobile | |||||
| mount Apis::Homeworks | mount Apis::Homeworks | ||||
| #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) | #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) | ||||
| #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? | |||||
| # add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) | |||||
| end | end | ||||
| end | end | ||||
| @@ -22,15 +22,15 @@ module RedmineApp | |||||
| # end | # end | ||||
| config.generators do |g| | config.generators do |g| | ||||
| g.test_framework :rspec, | |||||
| fixtures: true, | |||||
| view_specs: false, | |||||
| helper_specs: false, | |||||
| routing_specs: false, | |||||
| controller_specs: true, | |||||
| request_specs: false | |||||
| g.fixture_replacement :factory_girl, dir: "spec/factories" | |||||
| end | |||||
| g.test_framework :rspec, | |||||
| fixtures: true, | |||||
| view_specs: false, | |||||
| helper_specs: false, | |||||
| routing_specs: false, | |||||
| controller_specs: true, | |||||
| request_specs: false | |||||
| g.fixture_replacement :factory_girl, dir: "spec/factories" | |||||
| end | |||||
| # Custom directories with classes and modules you want to be autoloadable. | # Custom directories with classes and modules you want to be autoloadable. | ||||
| config.autoload_paths += %W(#{config.root}/lib) | config.autoload_paths += %W(#{config.root}/lib) | ||||
| @@ -11,7 +11,7 @@ | |||||
| # | # | ||||
| # It's strongly recommended to check this file into your version control system. | # It's strongly recommended to check this file into your version control system. | ||||
| ActiveRecord::Schema.define(:version => 20150128032421) do | |||||
| ActiveRecord::Schema.define(:version => 20150123020615) do | |||||
| create_table "activities", :force => true do |t| | create_table "activities", :force => true do |t| | ||||
| t.integer "act_id", :null => false | t.integer "act_id", :null => false | ||||
| @@ -925,7 +925,6 @@ ActiveRecord::Schema.define(:version => 20150128032421) do | |||||
| t.integer "attachmenttype", :default => 1 | t.integer "attachmenttype", :default => 1 | ||||
| t.integer "user_id" | t.integer "user_id" | ||||
| t.integer "dts_test", :default => 0 | t.integer "dts_test", :default => 0 | ||||
| t.string "enterprise_name" | |||||
| end | end | ||||
| add_index "projects", ["lft"], :name => "index_projects_on_lft" | add_index "projects", ["lft"], :name => "index_projects_on_lft" | ||||
| @@ -0,0 +1,11 @@ | |||||
| require 'spec_helper' | |||||
| describe AccountController do | |||||
| describe "showing up the login screen" do | |||||
| it "should start with login" do | |||||
| get :login | |||||
| response.should be_success | |||||
| end | |||||
| end | |||||
| end | |||||
| @@ -1,12 +0,0 @@ | |||||
| require 'spec_helper' | |||||
| describe EnterprisesController do | |||||
| describe "GET 'index'" do | |||||
| it "returns http success" do | |||||
| get 'index' | |||||
| response.should be_success | |||||
| end | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,189 @@ | |||||
| require 'spec_helper' | |||||
| describe PollController do | |||||
| # 创建测试数据 | |||||
| before do | |||||
| @poll=create(:poll) | |||||
| @poll_php=create(:poll,polls_name:'java',polls_group_id:'156') | |||||
| p @poll.errors | |||||
| p @poll_php.errors | |||||
| end | |||||
| # index动作的测试 | |||||
| # 错误分析:index测试,得到的polls为nil把,因为没传递任何参数,在index action中@course为nil, | |||||
| # 应该传参数poll_type = 'Course',参考before_filter: find_container,is_member_of_course中的代码 | |||||
| describe "GET index" do | |||||
| it "assigns all polls as @polls" do | |||||
| # @poll = Poll.create! valid_attributes | |||||
| # get请求,index动作,传入的参数 | |||||
| #get :index, {:id => @poll.to_param}, {} | |||||
| get :index,:poll => { :polls_type => @poll.polls_type,:polls_group_id => @poll.polls_group_id } | |||||
| # 返回的实际值和期望值是否相等,用eq表示相等,不用“==” | |||||
| # 控制器实例化的变量通过:assigns(:variable_name)获取 | |||||
| expect(assigns(:polls)).to eq([@poll]) | |||||
| end | |||||
| # 返回指定的模板 | |||||
| it"renders the index view"do | |||||
| get :index | |||||
| #控制其动作的返回浏览器的结果可以使用respond获取,此处返回的结果是渲染index模板 | |||||
| expect(response).to render_template :index | |||||
| end | |||||
| end | |||||
| # 对show动作的测试 | |||||
| describe "GET show" do | |||||
| it "show poll as @poll" do | |||||
| get :show,id:@poll | |||||
| expect(assigns( :poll)).to eq @poll | |||||
| end | |||||
| it"render the show template"do | |||||
| @poll=create(:poll) | |||||
| get :show, id: @poll | |||||
| expect(response).to render_template :show | |||||
| end | |||||
| end | |||||
| #对new动作的测试 | |||||
| describe "GET new" do | |||||
| # it "assigns a new poll as @poll" do | |||||
| # get :new | |||||
| # expect(assigns( :poll)).to be_a_new( Poll) | |||||
| # end | |||||
| # it " renders the :new template" do | |||||
| # get :new | |||||
| # expect(response).to render_template :new | |||||
| # end | |||||
| it "assigns a new poll as @poll" do | |||||
| get :new, {}, valid_session | |||||
| assigns(:poll).should be_a_new(Poll) | |||||
| end | |||||
| end | |||||
| #对edit动作的测试 | |||||
| describe 'GET edit' do | |||||
| it "assigns the requested poll to @poll" do | |||||
| # @poll = create(:poll) | |||||
| get :edit, id: @poll | |||||
| expect(assigns(:poll)).to eq @poll | |||||
| end | |||||
| it "renders the :edit template" do | |||||
| #@poll = create(:poll) | |||||
| get :edit, id: @poll | |||||
| expect(response).to render :layout => 'base_courses' | |||||
| end | |||||
| end | |||||
| #对update动作的测试 | |||||
| describe "PATCH update" do | |||||
| context "vaild attributes" do | |||||
| # 更新动作:输入合法,更新成功的情况 | |||||
| it"locates the requested @poll"do | |||||
| # attributes_for 方法生成的不是 Ruby 对象,而是一个由属性组成的 Hash,用来模拟浏览器和服务器之间的操作 | |||||
| put :update, id: @poll.id, poll: attributes_for( :poll) | |||||
| expect(assigns( :poll)).to eq(@poll) | |||||
| end | |||||
| #before{@poll = Poll.create! valid_attributes} | |||||
| it "assigns the requested poll as @poll" do | |||||
| # put :update ,{:id => @poll.to_param,:poll => valid_attributes}, valid_session | |||||
| # expect(assigns(:poll)).to eq @poll | |||||
| put :update,id:@poll,poll: attributes_for(:poll,polls_name:"china",polls_group_id:"1234") | |||||
| @poll.reload | |||||
| expect(@poll.polls_name).to eq("china") | |||||
| expect(@poll.polls_description).to eq("1234") | |||||
| end | |||||
| it "redirects to the poll" do | |||||
| put :update,id:@poll,poll:attributes_for(:poll) | |||||
| expect(response).to redirect_to @poll | |||||
| end | |||||
| end | |||||
| # 非法信息,更新失败的情况 | |||||
| context "invalid attributes" do | |||||
| it "update poll failure" do | |||||
| put :update,id:@poll,poll:attributes_for(:poll,polls_name:nil,polls_description:"test") | |||||
| @poll.reload | |||||
| expect(@poll.polls_name).to eq("php") | |||||
| expect(@poll.polls_description).to_not eq("test") | |||||
| end | |||||
| it "renders the 'edit' template" do | |||||
| # poll = Poll.create! valid_attributes | |||||
| # # Trigger the behavior that occurs when invalid params are submitted | |||||
| # Poll.any_instance.stub(:save).and_return(false) | |||||
| # put :update, {:id => poll.to_param, :poll => { "polls_name" => "invalid value" }}, valid_session | |||||
| # response.should render_template("edit") | |||||
| put :update,id:@poll,poll:attributes_for(:invalid_contact) | |||||
| expect(response).to render_template :edit | |||||
| end | |||||
| end | |||||
| end | |||||
| # describe "PUT update" do | |||||
| # context "with valid params" do | |||||
| # it "updates the requested poll" do | |||||
| # poll = Poll.create! valid_attributes | |||||
| # Poll.any_instance.should_receive(:update).with({ "polls_name" => "MyString" }) | |||||
| # put :update, {:id => poll.to_param, :poll => { "polls_name" => "MyString" }}, valid_session | |||||
| # end | |||||
| # | |||||
| # it "assigns the requested poll as @poll" do | |||||
| # @poll = Poll.create! valid_attributes | |||||
| # put :update, {:id => poll.to_param, :poll => valid_attributes}, valid_session | |||||
| # assigns(:poll).should eq(@poll) | |||||
| # end | |||||
| # | |||||
| # it "redirects to the poll" do | |||||
| # poll = Poll.create! valid_attributes | |||||
| # put :update, {:id => poll.to_param, :poll => valid_attributes}, valid_session | |||||
| # response.should redirect_to(poll) | |||||
| # end | |||||
| # end | |||||
| # | |||||
| # context "with invalid params" do | |||||
| # it "assigns the poll as @poll" do | |||||
| # poll = Poll.create! valid_attributes | |||||
| # Poll.any_instance.stub(:save).and_return(false) | |||||
| # put :update, {:id => poll.to_param, :poll => { "polls_name" => "invalid value" }}, valid_session | |||||
| # assigns(:poll).should eq(poll) | |||||
| # end | |||||
| # | |||||
| # it "re-renders the 'edit' template" do | |||||
| # poll = Poll.create! valid_attributes | |||||
| # Poll.any_instance.stub(:save).and_return(false) | |||||
| # put :update, {:id => poll.to_param, :poll => { "polls_name" => "invalid value" }}, valid_session | |||||
| # response.should render_template("edit") | |||||
| # end | |||||
| # end | |||||
| # end | |||||
| # #对create动作的测试 | |||||
| # describe "POST create" do | |||||
| # it"should redirect to index with a notice on successful save"do | |||||
| # Poll.any_instance.stubs(:valid?).returns(true) | |||||
| # post 'create' | |||||
| # response.should redirect_to(poll_path) | |||||
| # end | |||||
| # it"should re-render new template on failed save"do | |||||
| # Poll.any_instance.stubs(:valid).returns(false) | |||||
| # response.should render_template('new') | |||||
| # end | |||||
| # end | |||||
| #对delete动作的测试 | |||||
| describe "DELETE destroy" do | |||||
| it "destroy the requested poll" do | |||||
| poll = Poll.create! valid_attributes | |||||
| # delete请求,destroy动作,参数(可选),session(可选) | |||||
| expect{ delete :destroy,{:id=>poll.to_param},valid_session }.to change(Poll,:count).by(-1) | |||||
| end | |||||
| it "redirects to the polls list" do | |||||
| poll = Poll.create! valid_attributes | |||||
| # delete :destroy,id:@poll | |||||
| # expect(response).to redirect_to poll_path | |||||
| delete :destroy, {:id => poll.to_param}, valid_session | |||||
| response.should redirect_to(poll_url) | |||||
| end | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,6 @@ | |||||
| FactoryGirl.define do | |||||
| factory :course do | |||||
| tea_id 3622 | |||||
| name "php" | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,8 @@ | |||||
| FactoryGirl.define do | |||||
| factory :poll_questions do | |||||
| association :poll | |||||
| question_title "php" | |||||
| poll_id "" | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,13 @@ | |||||
| FactoryGirl.define do | |||||
| factory :poll do | |||||
| polls_name "php" | |||||
| polls_type "Course" | |||||
| polls_group_id 150 | |||||
| polls_status 2 | |||||
| user_id 3622 | |||||
| published_at "2015-02-01 10:25:15" | |||||
| closed_at "2015-02-01 10:25:15" | |||||
| polls_description "abc" | |||||
| show_result 1 | |||||
| end | |||||
| end | |||||
| @@ -1,5 +1,4 @@ | |||||
| require 'faker' | require 'faker' | ||||
| FactoryGirl.define do | FactoryGirl.define do | ||||
| factory :user do | factory :user do | ||||
| login "ExampleUser" | login "ExampleUser" | ||||
| @@ -0,0 +1,26 @@ | |||||
| require 'spec_helper' | |||||
| describe News do | |||||
| before do | |||||
| @news=News.new(title: 'test title',summary:'info',description: 'info about new') | |||||
| end | |||||
| subject { @news } | |||||
| # 属性存在性的测试 | |||||
| it { should respond_to(:title) } | |||||
| it { should respond_to(:description) } | |||||
| # 标题长度测试 | |||||
| describe "when the title is too long " do | |||||
| before { @news.title='a'*61 } | |||||
| it { should_not be_valid } | |||||
| end | |||||
| describe "when the summary is too long" do | |||||
| before { @news.summary='a'*256 } | |||||
| it { should_not be_valid } | |||||
| end | |||||
| describe "when the description is too long" do | |||||
| before { @news.description='a'*10001 } | |||||
| it { should_not be_valid } | |||||
| end | |||||
| end | |||||
| @@ -35,4 +35,7 @@ RSpec.configure do |config| | |||||
| # the seed, which is printed after each run. | # the seed, which is printed after each run. | ||||
| # --seed 1234 | # --seed 1234 | ||||
| config.order = "random" | config.order = "random" | ||||
| # 简化生成测试数据的语法 | |||||
| config.include FactoryGirl::Syntax::Methods | |||||
| end | end | ||||