ruby on rails - API test writes in dev db but reads in test db -


i'm trying test api airborne

the call api works , create user, in dev db : there no log of creation , find using rails c.

but when user.find in test, searches test db : there logs , doesn't find user.

here's test :

require 'rails_helper'  describe 'register#create'   'should create new user'     post '/register',     {       email: 'mail@mail.fr',       password: '12345678',       password_confirmation: '12345678'     }     puts response.body     expect_status 200     expect(user.find_by_email('mail@mail.fr')).to exist   end end 

here's method i'm trying test :

class registrationscontroller < devise::registrationscontroller       respond_to :json       skip_before_filter :verify_authenticity_token        acts_as_token_authentication_handler_for user       skip_before_filter :authenticate_entity_from_token!, only: [:create]       skip_before_filter :authenticate_entity!, only: [:create]        skip_before_filter :authenticate_scope!       append_before_filter :authenticate_scope!, only: [:destroy]        def create         build_resource(sign_up_params)          if !resource.valid?           status = 422           message = "#{resource.errors.full_messages}"         elsif resource.save!           status = 200           message = "successfully created new account email #{sign_up_params[:email]}."         else           clean_up_passwords resource           status = 500           message = "failed create new account email #{sign_up_params[:email]}."         end          respond_to |format|           format.json { render json: { message: message }, status: status }         end       end 

here's rails_helper :

env['rails_env'] = 'test'  require file.expand_path('../../config/environment', __file__) abort("the rails environment running in production mode!") if rails.env.production? require 'spec_helper' require 'rspec/rails'  activerecord::migration.maintain_test_schema!  rspec.configure |config|   config.fixture_path = "#{::rails.root}/spec/fixtures"   config.use_transactional_fixtures = true   config.infer_spec_type_from_file_location! end 

here's spec_helper :

env['rails_env'] = 'test'  require 'airborne'  airborne.configure |config|   config.base_url = 'http://myapp.dev/api/v1' end  rspec.configure |config|   config.expect_with :rspec |expectations|     expectations.include_chain_clauses_in_custom_matcher_descriptions = true   end    config.mock_with :rspec |mocks|     mocks.verify_partial_doubles = true   end end 

and finally, here's log :

$ rspec warn: unresolved specs during gem::specification.reset:       minitest (~> 5.1) warn: clearing out unresolved specs. please report bug if causes problems. debug -- :   activerecord::schemamigration load (0.1ms)  select "schema_migrations".* "schema_migrations" debug -- :    (0.1ms)  begin transaction {"message":"successfully created new account email mail@mail.fr."} debug -- :   user load (0.2ms)  select  "users".* "users" "users"."email" = ? limit 1  [["email", "mail@mail.fr"]] debug -- :    (0.1ms)  rollback transaction f  failures:    1) register#create should create new user      failure/error: expect(user.find_by_email('mail@mail.fr')).to exist        expected nil exist not respond either `exist?` or `exists?`      # ./spec/registration_controller_spec.rb:19:in `block (2 levels) in <top (required)>' 

i'm new rails , don't know problem might come from.

thanks :)

in test, post http://myapp.dv/api/v1/register pow! url.

pow! configuration default one, points dev env.

so test in right env, not call api.

i used powder switch envs , works.

ps : replaced

expect(user.find_by_email('mail@mail.fr')).to exist 

with

expect(user.find_by_email('mail@mail.fr')).not_to be_nil 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -