Skip to content
This repository was archived by the owner on Jun 6, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
/tmp

/Gemfile.lock

/coverage
17 changes: 17 additions & 0 deletions app/models/upload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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
2 changes: 2 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
exec $(dirname $0)/spring rspec "$@"
18 changes: 18 additions & 0 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions db/migrate/20131011162152_create_uploads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateUploads < ActiveRecord::Migration
def change
create_table :uploads do |t|
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

t.timestamps
end
end
end
27 changes: 27 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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 "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"
t.datetime "created_at"
t.datetime "updated_at"
end

end
10 changes: 10 additions & 0 deletions spec/factories/uploads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :upload do
filename "xx.png"
ext ".png"
content_type "image/png"
data "asdf"
end
end
21 changes: 21 additions & 0 deletions spec/models/upload_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe Upload do
let(:upload) { FactoryGirl.build :upload }
describe "validations" do
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