Navigation Menu

Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
More development improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalcora committed Nov 6, 2012
1 parent 97ba140 commit b792ac8
Show file tree
Hide file tree
Showing 22 changed files with 547 additions and 538 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -5,4 +5,4 @@ pkg/
tmp
.rspec
*.DS_Store
spec/config.yml
spec/dropbox.yml
1 change: 1 addition & 0 deletions Rakefile
@@ -1,6 +1,7 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require "paperclip/dropbox/rake"
import 'lib/paperclip/dropbox/tasks/authorize.rake'

Bundler.setup

Expand Down
5 changes: 0 additions & 5 deletions spec/config.example.yml

This file was deleted.

5 changes: 0 additions & 5 deletions spec/dropbox.yml

This file was deleted.

5 changes: 5 additions & 0 deletions spec/dropbox.yml.example
@@ -0,0 +1,5 @@
app_key: ""
app_secret: ""
access_token: ""
access_token_secret: ""
user_id: ""
26 changes: 13 additions & 13 deletions spec/paperclip/storage/dropbox_spec.rb
Expand Up @@ -49,22 +49,22 @@ def set_options(options)
end

it "accepts a path to file" do
set_options(dropbox_credentials: "#{RSPEC_DIR}/dropbox.yml")
set_options(dropbox_credentials: CREDENTIALS_FILE)
expect { User.new.avatar }.to_not raise_error(KeyError)
end

it "accepts an open file" do
set_options(dropbox_credentials: File.open("#{RSPEC_DIR}/dropbox.yml"))
set_options(dropbox_credentials: File.open(CREDENTIALS_FILE))
expect { User.new.avatar }.to_not raise_error(KeyError)
end

it "accepts a hash" do
set_options(dropbox_credentials: YAML.load(ERB.new(File.read("#{RSPEC_DIR}/dropbox.yml")).result))
set_options(dropbox_credentials: CREDENTIALS)
expect { User.new.avatar }.to_not raise_error(KeyError)
end

it "recognizes environments" do
hash = YAML.load(ERB.new(File.read("#{RSPEC_DIR}/dropbox.yml")).result)
hash = YAML.load(ERB.new(File.read(CREDENTIALS_FILE)).result)

set_options(dropbox_credentials: {development: hash}, dropbox_options: {environment: "development"})
expect { User.new.avatar }.to_not raise_error(KeyError)
Expand All @@ -79,7 +79,7 @@ def set_options(options)
stub_const("User", Class.new(ActiveRecord::Base) do
has_attached_file :avatar,
storage: :dropbox,
dropbox_credentials: "#{RSPEC_DIR}/dropbox.yml",
dropbox_credentials: CREDENTIALS_FILE,
dropbox_options: options,
styles: {medium: "300x300"}
end)
Expand Down Expand Up @@ -125,7 +125,7 @@ def set_options(options)
class User < ActiveRecord::Base
has_attached_file :avatar,
storage: :dropbox,
dropbox_credentials: "#{RSPEC_DIR}/dropbox.yml"
dropbox_credentials: CREDENTIALS_FILE
end
end

Expand All @@ -136,15 +136,15 @@ class User < ActiveRecord::Base
"Public/photo_with_spaces.jpg".should_not be_on_dropbox
end

after(:all) { Object.send(:remove_const, "User") }
after(:all) { Object.send(:remove_const, :User) }
end

describe "#url" do
before(:all) do
class User < ActiveRecord::Base
has_attached_file :avatar,
storage: :dropbox,
dropbox_credentials: "#{RSPEC_DIR}/dropbox.yml",
dropbox_credentials: CREDENTIALS_FILE,
styles: {medium: "300x300"}
end
end
Expand Down Expand Up @@ -173,7 +173,7 @@ class User < ActiveRecord::Base
response.code.to_i.should == 200
end

after(:each) { @user.destroy }
after(:each) { @user.destroy if not @user.nil? }

after(:all) { Object.send(:remove_const, :User) }
end
Expand All @@ -183,7 +183,7 @@ class User < ActiveRecord::Base
class User < ActiveRecord::Base
has_attached_file :avatar,
storage: :dropbox,
dropbox_credentials: "#{RSPEC_DIR}/dropbox.yml"
dropbox_credentials: CREDENTIALS_FILE
end
end

Expand All @@ -198,7 +198,7 @@ class User < ActiveRecord::Base
expect { User.create(avatar: uploaded_file("photo.jpg", "image/jpeg")) }.to raise_error(Paperclip::Storage::Dropbox::FileExists)
end

after(:each) { @user.destroy }
after(:each) { @user.destroy if not @user.nil? }
end

describe "update" do
Expand All @@ -216,7 +216,7 @@ class User < ActiveRecord::Base
"Public/another_photo.jpg".should be_on_dropbox
end

after(:each) { @user.destroy }
after(:each) { @user.destroy if not @user.nil? }
end

describe "destroy" do
Expand All @@ -232,7 +232,7 @@ class User < ActiveRecord::Base
expect { @user.destroy }.to_not raise_error
end

after(:each) { @user.destroy }
after(:each) { @user.destroy if not @user.nil? }
end

after(:all) do
Expand Down
21 changes: 17 additions & 4 deletions spec/spec_helper.rb
Expand Up @@ -6,7 +6,16 @@
RSPEC_DIR = File.expand_path(File.dirname(__FILE__))
Dir[File.join(RSPEC_DIR, "support/**/*.rb")].each { |f| require f }

CONFIG = YAML.load(File.read("#{RSPEC_DIR}/config.yml")).symbolize_keys
CREDENTIALS_FILE = "#{RSPEC_DIR}/dropbox.yml"

if File.exists?(CREDENTIALS_FILE)
CREDENTIALS = YAML.load(ERB.new(File.read(CREDENTIALS_FILE)).result).symbolize_keys
else
puts "\n### ERROR ###"
puts "Credential file not found at #{CREDENTIALS_FILE}"
puts "Copy dropbox.yml.example and fill in your app credentials.\n\n"
raise 'credential file not found'
end

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
Expand All @@ -15,9 +24,13 @@
VCR.configure do |config|
config.cassette_library_dir = 'spec/vcr_cassettes'
config.hook_into :fakeweb
config.default_cassette_options = {serialize_with: :syck}
config.filter_sensitive_data('API_KEY') { CONFIG[:app_key] }
config.filter_sensitive_data('ACCESS_TOKEN') { CONFIG[:app_secret] }
CREDENTIALS.keys.each do |key|
config.filter_sensitive_data("<#{key.to_s.upcase}>") { CREDENTIALS[key] }
end
config.default_cassette_options = {
serialize_with: :syck,
record: :new_episodes
}
config.configure_rspec_metadata!
config.allow_http_connections_when_no_cassette = true
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b792ac8

Please sign in to comment.