Hi, all.

I'm making an app using Padrino with Sequel.

In order to easy my work I made an utility function that creates a basic 
user where I can provide just a basic info (username and password) and all 
remaining fields are filled with predefined values.

Then I made a test application. My problem is that even having all fields 
being filled (and tests assure this), when I call save method in model I 
get a NotNullConstraintViolation exception.

Looking at the error message we can see that in fact almost no fields are 
filled in SQL .

←[0m←[1000D←[KERROR["test_0041_creates a client account using 
get_new_client. All data filled.", #<Class:0x404ccb8>, 0.006001]
 test_0041_creates a client account using get_new_client. All data filled.#User 
Model (0.01s)
Sequel::NotNullConstraintViolation:         Sequel::
NotNullConstraintViolation: PG::NotNullViolation: ERROR:  null value in 
column "username" violates not-null
constraint
        DETAIL:  Failing row contains (7, null, null, null, null, null, null
, t, t, null, 0, 0, C, T, 2014-09-14 16:35:48.155, null).


But why ? The model has it's fields filled. Can you please take a look at 
both the model snippet and unit test snippet and tell me what am I doing 
wrong?

I'm using Sequel 4.14.0. The problem happens on both Postgres and SQLite 
databases.

Ay help is very appreciated.

Thanks in advance.


Snippet of my My user model:

class User < Sequel::Model

  set_allowed_columns :username, :password, :points
  attr_accessor :username, :password, :points, :trial_expires_at, :role, :
fullname, :about, :status, :uuid
  attr_reader :created_at, :updated_at, :trial_expires_at

  def self.get_new_client(username, password, fullname = nil, about = nil)
      get_new_user(username, password, Constants::POINTS_INITIAL_VALUE, 
Constants::USER_TRIAL_TIME, UserRole::CLIENT, fullname, about)
  end

  def self.get_new_user(username, passwd, points, days_to_try, role=UserRole
.Client, fullname='', about='')
    ...
  end

end

Note: Other id, only username and password don't allow nulls.

Snippet of my test:

DB = Sequel::Model.db
DB.loggers << Logger.new($stdout)
users = DB[:users]

describe "User Model" do

  it 'creates a client account using get_new_client. All required data is 
filled.' do

    u = User.get_new_client('username', 'password', 'Regular Joe', 'Just a 
guy')

    refute_nil u
    'UserName'.downcase.must_equal u.username # it assures :username is 
filled
    u.password.must_equal "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8" # it 
assures :password is filled

    u.created_at.must_be_nil # a default value will be used in database
    u.updated_at.must_be_nil # it will be updated by a database's trigger
    
    u.points.must_equal Constants::POINTS_INITIAL_VALUE
    u.role.must_equal UserRole::CLIENT
    u.fullname.must_equal 'Regular Joe'
    u.about.must_equal 'Just a guy'
    u.status.must_equal UserStatus::TRIAL

    diff = (Time.now + Constants::USER_TRIAL_TIME) - u.trial_expires_at
    diff.must_be_close_to 0

    refute_nil u.uuid
    u.uuid.size.must_equal 36

    u.save if ! u.username.nil? # This causes the exception 
NotNullConstraintViolation. Did you see a redundant test to check username 
is not null?

  end

end

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to