diff --git a/.gitignore b/.gitignore index 8717e6c6..e024948b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ log/*.log tmp/**/* .idea .rspec +vendor/bundle diff --git a/app/models/asset.rb b/app/models/asset.rb new file mode 100644 index 00000000..d04624d5 --- /dev/null +++ b/app/models/asset.rb @@ -0,0 +1,17 @@ +# Copyright (C) 2011 Sergey Yanovich +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# Please see ./COPYING for details + +class Asset < ActiveRecord::Base + validates_presence_of :tag + validates_uniqueness_of :tag + has_many :deal_gives, :class_name => "Deal", :as => :give + has_many :deal_takes, :class_name => "Deal", :as => :take +end + +# vim: ts=2 sts=2 sw=2 et: diff --git a/app/models/resource.rb b/app/models/money.rb similarity index 78% rename from app/models/resource.rb rename to app/models/money.rb index 0c731ce0..f06657aa 100644 --- a/app/models/resource.rb +++ b/app/models/money.rb @@ -7,13 +7,6 @@ # # Please see ./COPYING for details -class Asset < ActiveRecord::Base - validates_presence_of :tag - validates_uniqueness_of :tag - has_many :deal_gives, :class_name => "Deal", :as => :give - has_many :deal_takes, :class_name => "Deal", :as => :take -end - class Money < ActiveRecord::Base validates_presence_of :num_code validates_presence_of :alpha_code diff --git a/spec/models/asset_spec.rb b/spec/models/asset_spec.rb new file mode 100644 index 00000000..f82274a3 --- /dev/null +++ b/spec/models/asset_spec.rb @@ -0,0 +1,20 @@ +# Copyright (C) 2011 Sergey Yanovich +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# Please see ./COPYING for details + +require 'spec_helper' + +describe Asset do + it "should have next behaviour" do + Factory(:asset) + should validate_presence_of :tag + should validate_uniqueness_of :tag + should have_many :deal_gives + should have_many :deal_takes + end +end diff --git a/spec/models/money_spec.rb b/spec/models/money_spec.rb new file mode 100644 index 00000000..e265b797 --- /dev/null +++ b/spec/models/money_spec.rb @@ -0,0 +1,23 @@ +# Copyright (C) 2011 Sergey Yanovich +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# Please see ./COPYING for details + +require 'spec_helper' + +describe Money do + it "should have next behaviour" do + Factory(:money) + should validate_presence_of :num_code + should validate_presence_of :alpha_code + should validate_uniqueness_of :num_code + should validate_uniqueness_of :alpha_code + should have_many :deal_gives + should have_many :deal_takes + should have_many :quotes + end +end diff --git a/spec/support/factories/factories.rb b/spec/support/factories/factories.rb index f0d6bb97..a8e67eb2 100644 --- a/spec/support/factories/factories.rb +++ b/spec/support/factories/factories.rb @@ -11,4 +11,13 @@ factory :entity do |e| e.sequence(:tag) { |n| "entity#{n}" } end + + factory :asset do |a| + a.sequence(:tag) { |n| "asset#{n}" } + end + + factory :money do |m| + m.sequence(:alpha_code) { |n| "MN#{n}" } + m.sequence(:num_code) { |n| n } + end end diff --git a/test/unit/resource_test.rb b/test/unit/resource_test.rb deleted file mode 100644 index c88a4b71..00000000 --- a/test/unit/resource_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2011 Sergey Yanovich -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3 of the -# License, or (at your option) any later version. -# -# Please see ./COPYING for details - -require 'test_helper' - -class ResourceTest < ActiveSupport::TestCase - test "resource" do - asset_should_store - money_should_store - end - - private - def asset_should_store - a = Asset.new - assert !a.save, "Asset with empty tag saved" - a.tag = assets(:aasiishare).tag - assert !a.save, "Asset with repeating tag saved" - end - - def money_should_store - m = Money.new - m.num_code = 840 - m.alpha_code = money(:rub).alpha_code - assert !m.save, "Money with repeating tag saved" - m = Money.new - assert !m.save, "Money with empty num_code and alpha_code saved" - m.num_code = 643 - assert !m.save, "Money with empty alpha_code saved" - m.alpha_code = "RUB" - assert !m.save, "Copy of rub money is saved" - end -end - -# vim: ts=2 sts=2 sw=2 et: