From 3a12b86d977037b09730e2e23ae850e822dfce64 Mon Sep 17 00:00:00 2001 From: raduwen Date: Sat, 12 Oct 2013 01:22:58 +0900 Subject: [PATCH 1/3] wip --- app/models/upload.rb | 2 ++ db/migrate/20131011162152_create_uploads.rb | 8 ++++++++ spec/factories/uploads.rb | 6 ++++++ spec/models/upload_spec.rb | 5 +++++ 4 files changed, 21 insertions(+) create mode 100644 app/models/upload.rb create mode 100644 db/migrate/20131011162152_create_uploads.rb create mode 100644 spec/factories/uploads.rb create mode 100644 spec/models/upload_spec.rb diff --git a/app/models/upload.rb b/app/models/upload.rb new file mode 100644 index 0000000..9626957 --- /dev/null +++ b/app/models/upload.rb @@ -0,0 +1,2 @@ +class Upload < ActiveRecord::Base +end diff --git a/db/migrate/20131011162152_create_uploads.rb b/db/migrate/20131011162152_create_uploads.rb new file mode 100644 index 0000000..e385816 --- /dev/null +++ b/db/migrate/20131011162152_create_uploads.rb @@ -0,0 +1,8 @@ +class CreateUploads < ActiveRecord::Migration + def change + create_table :uploads do |t| + + t.timestamps + end + end +end diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb new file mode 100644 index 0000000..09c9b6e --- /dev/null +++ b/spec/factories/uploads.rb @@ -0,0 +1,6 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :upload do + end +end diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb new file mode 100644 index 0000000..f582e25 --- /dev/null +++ b/spec/models/upload_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Upload do + pending "add some examples to (or delete) #{__FILE__}" +end From a644fb791c0394c591a6487ffb22fec04ab9ff16 Mon Sep 17 00:00:00 2001 From: raduwen Date: Sat, 12 Oct 2013 01:41:40 +0900 Subject: [PATCH 2/3] wip --- .gitignore | 2 ++ bin/rspec | 2 ++ bin/spring | 18 ++++++++++++++ db/migrate/20131011162152_create_uploads.rb | 5 ++++ db/schema.rb | 26 +++++++++++++++++++++ spec/factories/uploads.rb | 3 +++ spec/models/upload_spec.rb | 6 ++++- 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100755 bin/rspec create mode 100755 bin/spring create mode 100644 db/schema.rb diff --git a/.gitignore b/.gitignore index ba1d63c..dd94029 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ /tmp /Gemfile.lock + +/coverage diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..bba8a9e --- /dev/null +++ b/bin/rspec @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +exec $(dirname $0)/spring rspec "$@" diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000..ce54348 --- /dev/null +++ b/bin/spring @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +# This is a special way of invoking the spring gem in order to +# work around the performance issue discussed in +# https://github.com/rubygems/rubygems/pull/435 + +glob = "{#{Gem::Specification.dirs.join(",")}}/spring-*.gemspec" +candidates = Dir[glob].to_a.sort_by { |c| Gem::Version.new(File.basename(c).split(/[-\.]/)[1...-1].join(".")) } + +spec = Gem::Specification.load(candidates.last) + +if spec + spec.activate + load spec.bin_file("spring") +else + $stderr.puts "Could not find spring gem in #{Gem::Specification.dirs.join(", ")}." + exit 1 +end diff --git a/db/migrate/20131011162152_create_uploads.rb b/db/migrate/20131011162152_create_uploads.rb index e385816..246ee95 100644 --- a/db/migrate/20131011162152_create_uploads.rb +++ b/db/migrate/20131011162152_create_uploads.rb @@ -1,6 +1,11 @@ class CreateUploads < ActiveRecord::Migration def change create_table :uploads do |t| + t.string :fiename, null: false + t.string :ext, null: false + t.binary :data, null: false + t.string :download_password_encrypt + t.string :delete_password_encrypt t.timestamps end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..42c4d0a --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20131011162152) do + + create_table "uploads", force: true do |t| + t.string "fiename", null: false + t.string "ext", null: false + t.binary "data", null: false + t.string "download_password_encrypt" + t.string "delete_password_encrypt" + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb index 09c9b6e..e29d431 100644 --- a/spec/factories/uploads.rb +++ b/spec/factories/uploads.rb @@ -2,5 +2,8 @@ FactoryGirl.define do factory :upload do + filename "xx.png" + ext ".png" + data "asdf" end end diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index f582e25..19afc72 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -1,5 +1,9 @@ require 'spec_helper' describe Upload do - pending "add some examples to (or delete) #{__FILE__}" + describe "validations" do + it { validates_presence_of :filenmae } + it { validates_presence_of :ext } + it { validates_presence_of :data } + end end From fc1659ff06538d6bb41a044fd67c9c90be59ba75 Mon Sep 17 00:00:00 2001 From: raduwen Date: Sat, 12 Oct 2013 02:48:03 +0900 Subject: [PATCH 3/3] wip --- app/models/upload.rb | 15 +++++++++++++++ db/migrate/20131011162152_create_uploads.rb | 7 ++++--- db/schema.rb | 3 ++- spec/factories/uploads.rb | 7 ++++--- spec/models/upload_spec.rb | 18 +++++++++++++++--- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index 9626957..648bd26 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -1,2 +1,17 @@ class Upload < ActiveRecord::Base + attr_accessor :delete_password + attr_accessor :download_password + + before_save :encrypt + + validates :filename, presence: true + validates :ext, presence: true + validates :content_type, presence: true + validates :data, presence: true + + private + + def encrypt + true + end end diff --git a/db/migrate/20131011162152_create_uploads.rb b/db/migrate/20131011162152_create_uploads.rb index 246ee95..6b6e252 100644 --- a/db/migrate/20131011162152_create_uploads.rb +++ b/db/migrate/20131011162152_create_uploads.rb @@ -1,9 +1,10 @@ class CreateUploads < ActiveRecord::Migration def change create_table :uploads do |t| - t.string :fiename, null: false - t.string :ext, null: false - t.binary :data, null: false + t.string :filename, null: false + t.string :ext, null: false + t.string :content_type, null: false + t.binary :data, null: false t.string :download_password_encrypt t.string :delete_password_encrypt diff --git a/db/schema.rb b/db/schema.rb index 42c4d0a..a915763 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,8 +14,9 @@ ActiveRecord::Schema.define(version: 20131011162152) do create_table "uploads", force: true do |t| - t.string "fiename", null: false + t.string "filename", null: false t.string "ext", null: false + t.string "content_type", null: false t.binary "data", null: false t.string "download_password_encrypt" t.string "delete_password_encrypt" diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb index e29d431..9e55b60 100644 --- a/spec/factories/uploads.rb +++ b/spec/factories/uploads.rb @@ -2,8 +2,9 @@ FactoryGirl.define do factory :upload do - filename "xx.png" - ext ".png" - data "asdf" + filename "xx.png" + ext ".png" + content_type "image/png" + data "asdf" end end diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 19afc72..69beeae 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -1,9 +1,21 @@ require 'spec_helper' describe Upload do + let(:upload) { FactoryGirl.build :upload } describe "validations" do - it { validates_presence_of :filenmae } - it { validates_presence_of :ext } - it { validates_presence_of :data } + it { should validate_presence_of :filename } + it { should validate_presence_of :ext } + it { should validate_presence_of :content_type } + it { should validate_presence_of :data } + context "when parameters is #{FactoryGirl.attributes_for(:upload).to_s}" do + it { expect(upload).to be_valid } + end + end + + describe "#encrypt" do + it "should accept encrypt before save" do + expect(upload).to receive(:encrypt).and_return(true) + upload.save + end end end