Forum: Ruby on Rails Salted hash login, postgresql, unit tests

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mattias B. (Guest)
on 2006-02-28 21:37
Hello,

I have tried to install the salted hash login generator by following the
quick start guide at:
http://wiki.rubyonrails.com/rails/pages/SaltedLogi....
Everything seems to work fine until I try to run the unit tests by doing
'rake test_units', then I get the following error message:

<error-message>
[brasse@keso login-test]$ rake test_units
(in /home/brasse/RAILS/login-test)
psql:db/development_structure.sql:29: NOTICE:  CREATE TABLE will create
implicit sequence "users_id_seq" for "serial" column "users.id"
psql:db/development_structure.sql:38: NOTICE:  ALTER TABLE / ADD PRIMARY
KEY will create implicit index "users_pkey" for table "users"
psql:db/development_structure.sql:46: ERROR:  must be owner of schema
public
/usr/bin/ruby -Ilib:test
"/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb"
"test/unit/localization_test.rb" "test/unit/user_test.rb"
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:200:in
`const_missing': uninitialized constant Test (NameError)
        from ./test/unit/../test_helper.rb:5
        from ./test/unit/localization_test.rb:3
        from
/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5
        from
/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5
rake aborted!
Command failed with status (1): [/usr/bin/ruby -Ilib:test
"/usr/lib/ruby/ge...]

(See full trace by running task with --trace)
</error-message>

Since I am a bit new to both ruby and rails I am having a hard time to
understand the error message or even know where to start looking. Is
there something missing from my installation. What does the line with
'const_missing' tell me?

If someone could give some pointers on what might be wrong it would be
great. Has anyone here got this to work with postgresql? If so, how
could I get rid or the first error message: 'ERROR:  must be owner of
schema public'?

Any help or pointers will be greatly appriciated!

Regards,
Mattias
Anthony DeRobertis (Guest)
on 2006-02-28 23:00
(Received via mailing list)
Mattias Brc3a4ndstrc3b6m wrote:


> psql:db/development_structure.sql:46: ERROR:  must be owner of schema
> public

Rails is trying to do something to the public schema in your (probably
test) database, and PostgreSQL is telling it it doesn't have permission
to do so. What is line 46 of db/development_structure.sql?
Mattias B. (Guest)
on 2006-03-01 00:06
Anthony DeRobertis wrote:
> Mattias Brc3a4ndstrc3b6m wrote:
>
>
>> psql:db/development_structure.sql:46: ERROR:  must be owner of schema
>> public
>
> Rails is trying to do something to the public schema in your (probably
> test) database, and PostgreSQL is telling it it doesn't have permission
> to do so. What is line 46 of db/development_structure.sql?

On that line I find:

COMMENT ON SCHEMA public IS 'Standard public schema';

For some reason I don't have the permission to set a comment on the
schema named public. My guess is that the file
db/development_structure.sql have been generated by the unit tests by
something like pg_dump. pg_dump does generate that little annoying line
at the end that only the postgres user can execute. Perhaps there is a
way for me to get access to the public schema? Or perhaps there is a way
for me to create my own schema and then a users table in that schema.
But then I don't know how to tell rails/salted hash login where to find
that table.

Any ideas?

Regards,
Mattias
Michael G. (Guest)
on 2006-03-01 00:50
(Received via mailing list)
On Mar 1, 2006, at 7:06 , Mattias Brändström wrote:

> COMMENT ON SCHEMA public IS 'Standard public schema';
>
> For some reason I don't have the permission to set a comment on the
> schema named public. My guess is that the file
> db/development_structure.sql have been generated by the unit tests by
> something like pg_dump.

You're on the right track. When a PostgreSQL database is created,
it's usually copied from template1 (unless another database is used
as a template), and the owner of the public schema in template1 is
often not the same user[1] as the user you use to run your tests. To
add or change a comment on an object, you need to be the object's
owner or a superuser.

I've worked around this by creating a separate database user for
running tests and have given this user superuser privileges. I'd be
interested to hear how others have dealt with this situation.

[1] PostgreSQL recently updated its users and groups to roles.

Michael G.
grzm myrealbox com
Craig W. (Guest)
on 2006-03-01 01:52
(Received via mailing list)
On Wed, 2006-03-01 at 07:49 +0900, Michael G. wrote:
> it's usually copied from template1 (unless another database is used
>
> Michael G.
> grzm myrealbox com
----
indeed and I think that it was Michael who was pushing me on the
postgres-users list too.

I ended up simply creating a schema other than public and put everything
in that schema and referenced the schema in database.yml

I ***think*** that if you name the schema with the same name as the
'user' that you won't have to specifically identify the schema in
database.yml but that seemed to be of little use beyond that.

And yes, as Michael alludes to...with Postgres >= 8.0, you can probably
change the owner of the schema 'public' but that wasn't ever the
intention of postgres developers so it seems to be a bad idea, even if
possible.

Craig
Mattias B. (Guest)
on 2006-03-01 14:37
Craig W. wrote:
>
> I ended up simply creating a schema other than public and put everything
> in that schema and referenced the schema in database.yml
>
> I ***think*** that if you name the schema with the same name as the
> 'user' that you won't have to specifically identify the schema in
> database.yml but that seemed to be of little use beyond that.
>

How do you reference the schema in database.yml? When I tried to create
a new schema with the same name as my user I still get the same error.

Regards,
Mattias
Craig W. (Guest)
on 2006-03-01 15:52
(Received via mailing list)
On Wed, 2006-03-01 at 13:37 +0100, Mattias Brändström wrote:
> How do you reference the schema in database.yml? When I tried to create
> a new schema with the same name as my user I still get the same error.
-----
schema_search_path: schema_name

development:
  adaptor: postgres
  database: depot_development
  username: dave
  password: who_knows
  port: 5432
  host: bigdaddy
  schema_search_path: my_schema

Craig
Anthony DeRobertis (Guest)
on 2006-03-01 17:11
(Received via mailing list)
Mattias Brc3a4ndstrc3b6m wrote:

> For some reason I don't have the permission to set a comment on the
> schema named public.

Apparently, because the user you're connecting as doesn't own it. Try
something like this from the psql console, as a PostgreSQL superuser:

test=# ALTER SCHEMA public OWNER TO rails_user
test=# \dn
        List of schemas
        Name        |  Owner
--------------------+----------
 information_schema | postgres
 pg_catalog         | postgres
 pg_toast           | postgres
 public             | rails_user
(4 rows)
Mattias B. (Guest)
on 2006-03-01 19:20
Craig W. wrote:
> On Wed, 2006-03-01 at 13:37 +0100, Mattias Brändström wrote:
>> How do you reference the schema in database.yml? When I tried to create
>> a new schema with the same name as my user I still get the same error.
> -----
> schema_search_path: schema_name
>

Nice! Now that error is gone. I still have some other strange error
left. This one  I guess is not postresql related:

<error-message>
[brasse@keso login-test]$ rake test_units
(in /home/brasse/RAILS/login-test)
psql:db/development_structure.sql:37: NOTICE:  CREATE TABLE will create
implicit sequence "users_id_seq" for "serial" column "users.id"
psql:db/development_structure.sql:46: NOTICE:  ALTER TABLE / ADD PRIMARY
KEY will create implicit index "users_pkey" for table "users"
/usr/bin/ruby -Ilib:test
"/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb"
"test/unit/localization_test.rb" "test/unit/user_test.rb"
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:200:in
`const_missing': uninitialized constant Test (NameError)
        from ./test/unit/../test_helper.rb:5
        from ./test/unit/localization_test.rb:3
        from
/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5
        from
/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5
rake aborted!
Command failed with status (1): [/usr/bin/ruby -Ilib:test
"/usr/lib/ruby/ge...]

(See full trace by running task with --trace)
</error-message>

I can't figure out what '`const_missing': uninitialized constant Test
(NameError)' means. Does anyone else know?

Regards,
Mattias
Anthony DeRobertis (Guest)
on 2006-03-01 20:13
(Received via mailing list)
Mattias Brc3a4ndstrc3b6m wrote:

> I can't figure out what '`const_missing': uninitialized constant Test
> (NameError)' means. Does anyone else know?

I've seen that when I used a too-old version of rake. What version of
rake are you using? (rake --version will tell).
Mattias B. (Guest)
on 2006-03-02 00:34
Anthony DeRobertis wrote:
> Mattias Brc3a4ndstrc3b6m wrote:
>
>> I can't figure out what '`const_missing': uninitialized constant Test
>> (NameError)' means. Does anyone else know?
>
> I've seen that when I used a too-old version of rake. What version of
> rake are you using? (rake --version will tell).

I'm running rake version 0.7.0. My guess is that 0.7.0 is the newest
version. I tried to run 'gem update rake' just to see what happened:

<error-message>
[root@keso brasse]# gem update rake
Upgrading installed gems...
Updating Gem source index for: http://gems.rubyforge.org
Attempting remote upgrade of rake
Attempting remote installation of 'rake'
Successfully installed rake-0.7.0
/usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__': no
such file to load -- rdoc/rdoc (LoadError)
        from /usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
        from /usr/lib/site_ruby/1.8/rubygems/doc_manager.rb:43:in
`generate_rdoc'
        from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:215:in
`execute'
        from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:214:in
`execute'
        from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:153:in
`execute'
        from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:781:in
`execute'
        from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:777:in
`execute'
        from /usr/lib/site_ruby/1.8/rubygems/command.rb:49:in `invoke'
        from /usr/lib/site_ruby/1.8/rubygems/cmd_manager.rb:94:in
`process_args'
        from /usr/lib/site_ruby/1.8/rubygems/cmd_manager.rb:67:in `run'
        from /usr/lib/site_ruby/1.8/rubygems/gem_runner.rb:13:in `run'
        from /usr/bin/gem:17
</error-message>

Again, I have no clue what this means. It says that is has intalled
rake-0.7.0 but then it has touble loading something called rdoc. Any
more clues for me? =)

Regards,
Mattias
This topic is locked and can not be replied to.