From: Jan Provaznik jprovazn@redhat.com
task https://www.aeolusproject.org/redmine/issues/1604 This new model saves only list of deployables enabled by admin. --- src/app/models/deployable.rb | 6 +++++ src/db/migrate/20110602123101_deployables.rb | 13 +++++++++++ src/spec/factories/deployable.rb | 5 ++++ src/spec/models/deployable_spec.rb | 29 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 0 deletions(-) create mode 100644 src/app/models/deployable.rb create mode 100644 src/db/migrate/20110602123101_deployables.rb create mode 100644 src/spec/factories/deployable.rb create mode 100644 src/spec/models/deployable_spec.rb
diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb new file mode 100644 index 0000000..e521ddd --- /dev/null +++ b/src/app/models/deployable.rb @@ -0,0 +1,6 @@ +class Deployable < ActiveRecord::Base + validates_presence_of :name + validates_uniqueness_of :name + validates_length_of :name, :maximum => 1024 + validates_presence_of :url +end diff --git a/src/db/migrate/20110602123101_deployables.rb b/src/db/migrate/20110602123101_deployables.rb new file mode 100644 index 0000000..71ed08c --- /dev/null +++ b/src/db/migrate/20110602123101_deployables.rb @@ -0,0 +1,13 @@ +class Deployables < ActiveRecord::Migration + def self.up + create_table :deployables do |t| + t.string :name, :null => false, :limit => 1024 + t.text :description, :null => false + t.string :url + end + end + + def self.down + drop_table :deployables + end +end diff --git a/src/spec/factories/deployable.rb b/src/spec/factories/deployable.rb new file mode 100644 index 0000000..d0f3f57 --- /dev/null +++ b/src/spec/factories/deployable.rb @@ -0,0 +1,5 @@ +Factory.define :deployable do |d| + d.sequence(:name) { |n| "deployable#{n}" } + d.url "http://warehouseurl/bucket/uuid" + d.description "deployable description" +end diff --git a/src/spec/models/deployable_spec.rb b/src/spec/models/deployable_spec.rb new file mode 100644 index 0000000..d91ef33 --- /dev/null +++ b/src/spec/models/deployable_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Deployable do + it "should have a name of reasonable length" do + deployable = Factory :deployable + [nil, '', 'x'*1025].each do |invalid_name| + deployable.name = invalid_name + deployable.should_not be_valid + end + deployable.name = 'x'*1024 + deployable.should be_valid + end + + it "should have unique name" do + deployable = Factory :deployable + second_deployable = Factory.build(:deployable, :name => deployable.name) + second_deployable.should_not be_valid + + second_deployable.name = 'unique name' + second_deployable.should be_valid + end + + it "should have a url" do + deployable = Factory :deployable + deployable.url = '' + deployable.should_not be_valid + end + +end