From 91c8be6b6c8e344a11c213f181482f56a19f7e1d Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 25 Jun 2013 13:04:55 +0200 Subject: [PATCH] make tests work again --- test/fixtures/articles.yml | 4 ---- test/fixtures/groups.yml | 7 ++----- test/fixtures/suppliers.yml | 13 ------------- test/test_helper.rb | 12 +++++++++++- test/unit/supplier_test.rb | 6 +++--- test/unit/user_test.rb | 35 ++++++++++++++++++++--------------- 6 files changed, 36 insertions(+), 41 deletions(-) diff --git a/test/fixtures/articles.yml b/test/fixtures/articles.yml index 125bd282..0bf03e48 100644 --- a/test/fixtures/articles.yml +++ b/test/fixtures/articles.yml @@ -1,8 +1,4 @@ # == Schema Information -<<<<<<< HEAD:test/fixtures/articles.yml -======= -# Schema version: 20090325175756 ->>>>>>> wiki:test/fixtures/articles.yml # # Table name: articles # diff --git a/test/fixtures/groups.yml b/test/fixtures/groups.yml index af0e71b4..c6152192 100644 --- a/test/fixtures/groups.yml +++ b/test/fixtures/groups.yml @@ -3,6 +3,7 @@ admins: type: Workgroup name: Administrators description: System administrators. + created_on: <%= 5.weeks.ago.to_s(:db) %> role_admin: true role_suppliers: true role_article_meta: true @@ -11,12 +12,8 @@ admins: bananas: type: Ordergroup name: Banangroup + created_on: <%= 4.weeks.ago.to_s(:db) %> account_balance: 100.00 - account_updated: <%= 1.weeks.ago.to_s(:db) %> contact_person: Tim contact_phone: 030 123132456 contact_address: Waldermarstrasse 43, 10988 Berlin - - - - diff --git a/test/fixtures/suppliers.yml b/test/fixtures/suppliers.yml index dc0a4049..4a2302c3 100644 --- a/test/fixtures/suppliers.yml +++ b/test/fixtures/suppliers.yml @@ -1,8 +1,4 @@ # == Schema Information -<<<<<<< HEAD:test/fixtures/suppliers.yml -======= -# Schema version: 20090325175756 ->>>>>>> wiki:test/fixtures/suppliers.yml # # Table name: suppliers # @@ -38,12 +34,3 @@ terra: Terra possibly delivers also on other days than tuesday. Don't hesitate to ask for it. min_order_quantity: 80,-€ (gross) - - - - - - - - - diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bf1192f..80fc4fc5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,5 +9,15 @@ class ActiveSupport::TestCase # -- they do not yet inherit this setting fixtures :all - # Add more helper methods to be used by all tests here... + def login(nick='admin', pass='secret') + open_session do |session| + session.post '/f/login', nick: nick, password: pass + end + end + + def logout + open_session do |session| + session.post '/f/logout' + end + end end diff --git a/test/unit/supplier_test.rb b/test/unit/supplier_test.rb index f8db2bf0..df82c6bf 100644 --- a/test/unit/supplier_test.rb +++ b/test/unit/supplier_test.rb @@ -1,18 +1,18 @@ require File.dirname(__FILE__) + '/../test_helper' -class SupplierTest < Test::Unit::TestCase +class SupplierTest < ActiveSupport::TestCase fixtures :suppliers def setup @supplier = Supplier.find_by_name("Terra") end - def test_read + test 'read' do assert_equal "Terra", @supplier.name assert_equal "www.terra-natur.de", @supplier.url end - def test_update + test 'update' do assert_equal "tuesday", @supplier.delivery_days @supplier.delivery_days = 'wednesday' assert @supplier.save, @supplier.errors.full_messages.join("; ") diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index c7223272..8f6228dc 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1,13 +1,13 @@ require File.dirname(__FILE__) + '/../test_helper' -class UserTest < Test::Unit::TestCase +class UserTest < ActiveSupport::TestCase fixtures :users def setup @admin = users(:admin) end - def test_read_user + test 'read_user' do assert_kind_of User, @admin assert_equal "Anton", @admin.first_name assert_equal "Admininistrator", @admin.last_name @@ -15,20 +15,25 @@ class UserTest < Test::Unit::TestCase assert @admin.role_admin? end - def test_create_and_read_password - @admin.set_password({:required => true}, "secret", "secret") + test 'create_and_read_password' do + @admin.password = "some_secret" + @admin.password_confirmation = @admin.password + assert @admin.valid? + assert @admin.has_password("some_secret") + end + + test 'invalid_password' do + @admin.password = "foo" + @admin.password_confirmation = @admin.password + assert @admin.invalid? + assert_equal [I18n.t('activemodel.errors.messages.too_short', count: 5)], @admin.errors[:password] + end + + test 'password_not_match' do + @admin.password = "foobar" + @admin.password_confirmation = "foobor" @admin.save - assert @admin.has_password("secret") - end - - def test_invalid_password - @admin.set_password({:required => true}, "foo", "foo") - assert_equal 'Passwort muss zwischen 6 u. 25 Zeichen haben', @admin.errors.on_base - end - - def test_password_not_match - @admin.set_password({:required => true}, "foobar", "foobor") - assert_equal 'Passworteingaben stimmen nicht überein', @admin.errors.on_base + assert_equal [I18n.t('activemodel.errors.messages.confirmation')], @admin.errors[:password] end end