ruby on rails - rspec request with devise not working to get current_user and response body nothing -


i new in ruby on rails. use rails 4 , devise application . use devse cancan authorization , authentification. tried try rsepc request. after visit user_session_path aplication don't response, , cannot current_user devise.

my code : */support/devise_support.rb

module validuserrequesthelper     def sign_in_as_a_valid_user        @user ||= factorygirl.create :user        visit user_session_path       fill_in "email", :with => @user.email       fill_in "password", :with => @user.password       click_button "sign in"     end end  rspec.configure |config|     config.include validuserrequesthelper, :type => :controller     config.include validuserrequesthelper, :type => :request end 

in spec_helper.rb

env["rails_env"] ||= 'test' require file.expand_path("../../config/environment", __file__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rspec'  capybara.javascript_driver = :webkit   dir[rails.root.join("spec/support/**/*.rb")].each { |f| require f }   activerecord::migration.check_pending! if defined?(activerecord::migration)  rspec.configure |config|    config.include devise::testhelpers, :type => :controller   config.include devise::testhelpers, :type => :view     capybara.javascript_driver = :webkit    config.fixture_path = "#{::rails.root}/spec/fixtures"     config.use_transactional_fixtures = true   config.include capybara::dsl    config.infer_base_class_for_anonymous_controllers = false    config.order = "random" end 

this configuration running wel in controller spec when try in request or view spec cannot current_user or cannot redirect home page after login (user_session_path)

this request spec

require "spec_helper"  describe "contact_view", :js => true   before     sign_in_as_a_valid_user    end   "test click", :driver => :webkit     visit "home/index"     puts page.html      click_button "button"   end end 

after run code output text above:

.<html><head></head><body></body></html> f  failures:    1) contact_view test click      failure/error: click_button "button"      capybara::elementnotfound:        unable find button "button"      # ./spec/requests/contact_spec.rb:27:in `block (2 levels) in <top (required)>' 

button element ready in view because user_session_path not redirect after login button element not found.

please me .. wrong in code??

update controller running

require "spec_helper"  describe homecontroller    before     sign_in_as_a_valid_user     sign_in @user     @user_param = {name:'zainul',phone:'0897741195',user_id:@user.id}     @param = {format:'json'}     post :create, @user_param.merge(@param)     @id = contact.find(@user.id)   end    describe "get #index"     "render :index view"       :index       flash[:notice].should match "welcome #{@user.email}"       response.status.should be(200)     end   end    describe "post #create"     "test assignment post"       response.body.should == true.to_json     end   end    describe "put #update"      "put update record in controller"       put :update, @param.merge({id:@id})       response.body.should == true.to_json     end    end    describe "delete #destroy"      "delete record in controller"       delete :destroy,@param.merge({id:@id})       response.body.should == true.to_json     end    end    describe "get #show"     "show record id controller show"       param_grid={rows:4,page:1,sidx:"id",sord:"asc",id:@id}       :show,@param.merge(param_grid)       response.should be_success       body = json.parse(response.body)       body.should include('rows')       rows = body['rows']       rows.should have(1).items     end   end end 


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -