Commit 09a5eb9349bac41979f982207d3b2aba2c1c0fa3
1 parent
13506f04
Exists in
master
and in
28 other branches
ActionItem0: adding box itens
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@30 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
78 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +class Box < ActiveRecord::Base | ||
2 | + belongs_to :owner, :polymorphic => true | ||
3 | + | ||
4 | + #we cannot have two boxs with the same number to the same owner | ||
5 | + validates_uniqueness_of :number, :scope => :owner | ||
6 | + | ||
7 | + #<tt>number</tt> must be a integer | ||
8 | + validates_numericality_of :number, :only_integer => true, :message => _('%{fn} must be composed only of integers.') | ||
9 | +end |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class CreateBoxes < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :boxes do |t| | ||
4 | + t.column :number, :integer | ||
5 | + t.column :owner_type, :string | ||
6 | + t.column :owner_id, :integer | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
10 | + def self.down | ||
11 | + drop_table :boxes | ||
12 | + end | ||
13 | +end |
@@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class BoxTest < Test::Unit::TestCase | ||
4 | + fixtures :boxes, :blocks | ||
5 | + | ||
6 | + def test_destroy | ||
7 | + count = Box.count | ||
8 | + assert Box.find(1).destroy | ||
9 | + assert_equal count - 1, Box.count | ||
10 | + end | ||
11 | + | ||
12 | + def test_create | ||
13 | + count = Box.count | ||
14 | + b = Box.new | ||
15 | + b.number = 2 | ||
16 | + assert b.save | ||
17 | + assert count + 1, Box.count | ||
18 | + end | ||
19 | + | ||
20 | + | ||
21 | + def test_number_format | ||
22 | + b = Box.new | ||
23 | + b.number = "none" | ||
24 | + assert !b.valid? | ||
25 | + assert b.errors.invalid?(:number) | ||
26 | + | ||
27 | + b = Box.new | ||
28 | + b.number = 10.2 | ||
29 | + assert !b.save | ||
30 | + | ||
31 | + b = Box.new | ||
32 | + b.number = 10 | ||
33 | + assert b.save | ||
34 | + | ||
35 | + end | ||
36 | + | ||
37 | + def test_unique_number | ||
38 | + assert Box.delete_all | ||
39 | + assert Box.create(:number => 1) | ||
40 | + | ||
41 | + b = Box.new(:number => 1) | ||
42 | + assert !b.valid? | ||
43 | + assert b.errors.invalid?(:number) | ||
44 | + end | ||
45 | + | ||
46 | +end |