please help correct test.

its a model User:
class User < ActiveRecord::Base
  before_save { self.email  = email.downcase  }
  before_create :create_remember_token

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence:     true,
                                      format:         { with:
VALID_EMAIL_REGEX },
                                      uniqueness: { case_sensitive:
false }
  validates :diary_name, presence: true, uniqueness: { case_sensitive:
false }
  validates :password,  length: { minimum:  6 }
  validates :name,  presence: true, length: { maximum:  50  },
uniqueness: { case_sensitive: false }

  has_secure_password

  has_many    :recalls
  has_many    :posts,  dependent:  :destroy
  belongs_to  :gender

  has_attached_file :avatar, :styles => { :large => "300x300>", :medium
=> "100x100>", :thumb => "30x30>" }
  validates_attachment_content_type :avatar, :content_type =>
["image/jpg", "image/jpeg", "image/png", "image/gif"]
  validates_attachment_file_name :avatar, :matches => [/png\Z/,
/jpe?g\Z/, /gif\Z/]
end

its a controller UserController:
class UsersController < ApplicationController
  def new
    @user = User.new
  end

  def create
    @user = User.new(user_params)

    if  @user.save
      sign_in @user
      flash[:success] = "Welcome  to  the Sample  App!"
      redirect_to  @user
    else
      flash.now[:error] = 'Invalid data'
      render  'new'
    end
  end

  private

    def user_params
      params.require(:user).permit(:name, :email, :diary_name,
:password, :gender_id, :password_confirmation, :phone, :skype, :info,
:avatar, :delete_avatar)
    end
end

its a fixture user:
one:
  name: 'onfge'
  email: 'mystrdf...@ad.ad'
  password_digest:
'$2a$10$XS2HLwMZxg/7yRKAWd9AJ.afCMra0wGWK4b.FhkY/qo3Lmo/tKEiO'
  remember_token: 'dc3461e13c8d316dad22332a503e06edafa0b9cb'
  phone: '43535345'
  skype: 'gggggg'
  gender: one
  info: 'MyString'
  admin: true
  avatar_file_name: nil
  avatar_content_type: nil
  avatar_file_size: nil

its a fixture genders:
one:
  gender_name: '-'

two:
  gender_name: 'male'

three:
  gender_name: 'female'


a test that does not work:
class UsersControllerTest < ActionController::TestCase
  fixtures :users

  setup do
    @user = users(:one)
    @input_attributes = {
        email: 'yhy...@ad.ad',
        gender_id: 1,
        info: 'u76u67u67u',
        name: 'fsdfsdf',
        password: 'qwerty',
        password_confirmation: 'qwerty',
        phone: '435345345',
        skype: 'sdggdfgdfgfdgd'
    }
  end

  test "should create user" do
    assert_difference('User.count') do
      post :create,
      user: @input_attributes
    end
  end
end


after a test run in the console I get the following error message:
  1) Failure:
UsersControllerTest#test_should_create_user
[/home/kalinin/rails/ZSUM/test/controllers/users_controller_test.rb:37]:
"User.count" didn't change by 1.
Expected: 3
  Actual: 2


It is the message that is logged. it is clear that the transaction is
rolled back for some strange reason:
  [1m[35mUser Load (0.1ms)[0m  SELECT  "users".* FROM "users" WHERE
"users"."id" = ? LIMIT 1  [["id", 980190962]]
  [1m[36m (0.1ms)[0m  [1mSELECT COUNT(*) FROM "users"[0m
Processing by UsersController#create as HTML
  Parameters: {"user"=>{"email"=>"yhy...@ad.ad", "gender_id"=>"1",
"info"=>"u76u67u67u", "name"=>"fsdfsdf", "password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]", "phone"=>"435345345",
"skype"=>"sdggdfgdfgfdgd"}}
  [1m[35m (0.1ms)[0m  SAVEPOINT active_record_1
  [1m[36mUser Exists (0.1ms)[0m  [1mSELECT  1 AS one FROM "users" WHERE
LOWER("users"."email") = LOWER('yhy...@ad.ad') LIMIT 1[0m
  [1m[35mUser Exists (0.1ms)[0m  SELECT  1 AS one FROM "users" WHERE
"users"."diary_name" IS NULL LIMIT 1
  [1m[36mUser Exists (0.1ms)[0m  [1mSELECT  1 AS one FROM "users" WHERE
LOWER("users"."name") = LOWER('fsdfsdf') LIMIT 1[0m
  [1m[35m (0.1ms)[0m  ROLLBACK TO SAVEPOINT active_record_1

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/06d53bb2afb02aafb44af773043879ed%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to