diff --git a/Gemfile b/Gemfile index 5b07e9c7..085d926f 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,8 @@ gem "htmlentities" gem "swf_fu" gem "rails_autolink" gem 'thin' +gem "cache_digests" +gem "paperclip" # To use ActiveModel has_secure_password gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index 909d1115..680805b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,6 +114,12 @@ GEM nokogiri rack (1.5.5) rack-dev-mark (0.7.3) + paperclip (4.1.1) + activemodel (>= 3.0.0) + activesupport (>= 3.0.0) + cocaine (~> 0.5.3) + mime-types + polyglot (0.3.5) rack (>= 1.1) rack-mini-profiler (0.9.2) rack (>= 1.1.3) @@ -228,6 +234,7 @@ DEPENDENCIES jquery-rails mocha mysql2 + paperclip rack-dev-mark rack-mini-profiler rails (~> 4.1.11) diff --git a/app/models/attachment.rb b/app/models/attachment.rb new file mode 100644 index 00000000..2b38bf51 --- /dev/null +++ b/app/models/attachment.rb @@ -0,0 +1,10 @@ +class Attachment < ActiveRecord::Base + belongs_to :todo, touch: true + + has_attached_file :file, + url: '/:class/:id/:basename.:extension', + path: ":rails_root/db/assets/#{Rails.env}/:class/:id/:basename.:extension" + + do_not_validate_attachment_file_type :file + # validates_attachment_content_type :file, :content_type => ["text/plain"] +end diff --git a/app/models/todo.rb b/app/models/todo.rb index 3f82e217..8e4ee7c6 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -25,6 +25,8 @@ class Todo < ActiveRecord::Base has_many :pending_successors, -> {where('todos.state = ?', 'pending')}, :through => :predecessor_dependencies, :source => :successor + has_many :attachments, dependent: :delete_all + # scopes for states of this todo scope :active, -> { where state: 'active' } scope :active_or_hidden, -> { where "todos.state = ? OR todos.state = ?", 'active', 'project_hidden' } diff --git a/db/migrate/20140703191545_create_attachments.rb b/db/migrate/20140703191545_create_attachments.rb new file mode 100644 index 00000000..277cfb19 --- /dev/null +++ b/db/migrate/20140703191545_create_attachments.rb @@ -0,0 +1,9 @@ +class CreateAttachments < ActiveRecord::Migration + def change + create_table :attachments do |t| + t.references :todo, index: true + t.attachment :file + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 37555542..c1726f04 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,23 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150209233951) do +ActiveRecord::Schema.define(version: 20140703191545) do + + create_table "attachments", force: true do |t| + t.integer "todo_id" + t.string "file_file_name" + t.string "file_content_type" + t.integer "file_file_size" + t.datetime "file_updated_at" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "attachments", ["todo_id"], name: "index_attachments_on_todo_id", using: :btree create_table "contexts", force: true do |t| t.string "name", null: false - t.integer "position" + t.integer "position", default: 0 t.integer "user_id", default: 1 t.datetime "created_at" t.datetime "updated_at" @@ -85,11 +97,11 @@ ActiveRecord::Schema.define(version: 20150209233951) do add_index "preferences", ["user_id"], name: "index_preferences_on_user_id", using: :btree create_table "projects", force: true do |t| - t.string "name", null: false - t.integer "position" - t.integer "user_id", default: 1 - t.text "description" - t.string "state", limit: 20, null: false + t.string "name", null: false + t.integer "position", default: 0 + t.integer "user_id", default: 1 + t.text "description", limit: 16777215 + t.string "state", limit: 20, null: false t.datetime "created_at" t.datetime "updated_at" t.integer "default_context_id" @@ -104,17 +116,17 @@ ActiveRecord::Schema.define(version: 20150209233951) do add_index "projects", ["user_id"], name: "index_projects_on_user_id", using: :btree create_table "recurring_todos", force: true do |t| - t.integer "user_id", default: 1 - t.integer "context_id", null: false + t.integer "user_id", default: 1 + t.integer "context_id", null: false t.integer "project_id" - t.string "description", null: false - t.text "notes" - t.string "state", limit: 20, null: false + t.string "description", null: false + t.text "notes", limit: 16777215 + t.string "state", limit: 20, null: false t.datetime "start_from" t.string "ends_on" t.datetime "end_date" - t.integer "number_of_occurrences" - t.integer "occurrences_count", default: 0 + t.integer "number_of_occurences" + t.integer "occurences_count", default: 0 t.string "target" t.integer "show_from_delta" t.string "recurring_period" @@ -141,7 +153,7 @@ ActiveRecord::Schema.define(version: 20150209233951) do t.datetime "updated_at" end - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree + add_index "sessions", ["session_id"], name: "sessions_session_id_index", using: :btree create_table "taggings", force: true do |t| t.integer "taggable_id" @@ -162,19 +174,19 @@ ActiveRecord::Schema.define(version: 20150209233951) do add_index "tags", ["name"], name: "index_tags_on_name", using: :btree create_table "todos", force: true do |t| - t.integer "context_id", null: false + t.integer "context_id", null: false t.integer "project_id" - t.string "description", null: false - t.text "notes" + t.string "description", null: false + t.text "notes", limit: 16777215 t.datetime "created_at" t.datetime "due" t.datetime "completed_at" - t.integer "user_id", default: 1 + t.integer "user_id", default: 1 t.datetime "show_from" - t.string "state", limit: 20, null: false + t.string "state", limit: 20, null: false t.integer "recurring_todo_id" t.datetime "updated_at" - t.text "rendered_notes" + t.text "rendered_notes", limit: 16777215 end add_index "todos", ["context_id"], name: "index_todos_on_context_id", using: :btree @@ -212,7 +224,7 @@ ActiveRecord::Schema.define(version: 20150209233951) do create_table "users", force: true do |t| t.string "login", limit: 80, null: false - t.string "crypted_password", limit: 60, null: false + t.string "crypted_password", limit: 60 t.string "token" t.boolean "is_admin", default: false, null: false t.string "first_name" diff --git a/test/fixtures/attachments.yml b/test/fixtures/attachments.yml new file mode 100644 index 00000000..b74dd212 --- /dev/null +++ b/test/fixtures/attachments.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + todo_id: + +two: + todo_id: diff --git a/test/models/attachment_test.rb b/test/models/attachment_test.rb new file mode 100644 index 00000000..ff491dc1 --- /dev/null +++ b/test/models/attachment_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class AttachmentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end