From 42e6fc6a68c2072b26354ab2768336c5658725c1 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 8 May 2014 18:03:48 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=B5=84=E6=BA=90=E7=B1=BB?= =?UTF-8?q?=E5=9E=8Bcontrol=E3=80=81model=E5=8F=8A=E8=A1=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84=202.=E8=B5=84=E6=BA=90(attachments)=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=88=86=E7=B1=BB=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 1 + app/models/attachmentstype.rb | 3 +++ .../20140508030039_create_attachmentstypes.rb | 12 ++++++++++++ ...20140508030358_add_attachtype_to_attachments.rb | 5 +++++ db/schema.rb | 14 ++------------ test/fixtures/attachmentstypes.yml | 9 +++++++++ test/unit/attachmentstype_test.rb | 7 +++++++ 7 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 app/models/attachmentstype.rb create mode 100644 db/migrate/20140508030039_create_attachmentstypes.rb create mode 100644 db/migrate/20140508030358_add_attachtype_to_attachments.rb create mode 100644 test/fixtures/attachmentstypes.yml create mode 100644 test/unit/attachmentstype_test.rb diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 73ae44b4d..792a1776d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -23,6 +23,7 @@ class Attachment < ActiveRecord::Base belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'" belongs_to :author, :class_name => "User", :foreign_key => "author_id" + belongs_to :attachmentstype, :foreign_key => "attachtype" validates_presence_of :filename, :author validates_length_of :filename, :maximum => 255 diff --git a/app/models/attachmentstype.rb b/app/models/attachmentstype.rb new file mode 100644 index 000000000..1d3c2cfcd --- /dev/null +++ b/app/models/attachmentstype.rb @@ -0,0 +1,3 @@ +class Attachmentstype < ActiveRecord::Base + attr_accessible :typeId, :typeName +end diff --git a/db/migrate/20140508030039_create_attachmentstypes.rb b/db/migrate/20140508030039_create_attachmentstypes.rb new file mode 100644 index 000000000..625686346 --- /dev/null +++ b/db/migrate/20140508030039_create_attachmentstypes.rb @@ -0,0 +1,12 @@ +class CreateAttachmentstypes < ActiveRecord::Migration + def self.up + create_table :attachmentstypes do |t| + t.column :typeId, :integer, :null => false + t.column :typeName, :string, :limit =>50 + end + end + + def self.down + drop_table :attachmentstypes + end +end \ No newline at end of file diff --git a/db/migrate/20140508030358_add_attachtype_to_attachments.rb b/db/migrate/20140508030358_add_attachtype_to_attachments.rb new file mode 100644 index 000000000..24a98839b --- /dev/null +++ b/db/migrate/20140508030358_add_attachtype_to_attachments.rb @@ -0,0 +1,5 @@ +class AddAttachtypeToAttachments < ActiveRecord::Migration + def change + add_column :attachments, :attachtype, :int + end +end diff --git a/db/schema.rb b/db/schema.rb index fe23a1caa..2ff8ca006 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140428013546) do +ActiveRecord::Schema.define(:version => 20140508030358) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -36,6 +36,7 @@ ActiveRecord::Schema.define(:version => 20140428013546) do t.datetime "created_on" t.string "description" t.string "disk_directory" + t.integer "attachtype" end add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id" @@ -755,11 +756,6 @@ ActiveRecord::Schema.define(:version => 20140428013546) do add_index "time_entries", ["project_id"], :name => "time_entries_project_id" add_index "time_entries", ["user_id"], :name => "index_time_entries_on_user_id" - create_table "tmp", :force => true do |t| - t.string "name" - t.string "part_number" - end - create_table "tokens", :force => true do |t| t.integer "user_id", :default => 0, :null => false t.string "action", :limit => 30, :default => "", :null => false @@ -966,10 +962,4 @@ ActiveRecord::Schema.define(:version => 20140428013546) do add_index "workflows", ["role_id", "tracker_id", "old_status_id"], :name => "wkfs_role_tracker_old_status" add_index "workflows", ["role_id"], :name => "index_workflows_on_role_id" - create_table "yans", :force => true do |t| - t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - end diff --git a/test/fixtures/attachmentstypes.yml b/test/fixtures/attachmentstypes.yml new file mode 100644 index 000000000..429b31b4b --- /dev/null +++ b/test/fixtures/attachmentstypes.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + typeId: + typeName: + +two: + typeId: + typeName: diff --git a/test/unit/attachmentstype_test.rb b/test/unit/attachmentstype_test.rb new file mode 100644 index 000000000..0dcee4479 --- /dev/null +++ b/test/unit/attachmentstype_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class AttachmentstypeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end