Skip to content

Instantly share code, notes, and snippets.

@rjswenson
Last active August 29, 2015 14:02
Show Gist options
  • Save rjswenson/9725ab561e11f4487125 to your computer and use it in GitHub Desktop.
Save rjswenson/9725ab561e11f4487125 to your computer and use it in GitHub Desktop.
# Assets are images that need no resampling, fonts, etc, that
# are used for the site. Examples are catalog landing pages,
# carousel images, etc.
class Asset
include Mongoid::Document
include Mongoid::Paperclip
field :type
field :catalog_key
field :category
field :position
field :file_hash
field :original_filename
PAPERCLIP_SETTINGS = {
'development' => {
:path => ':rails_root/tmp/import/assets/processed/:style-:filename',
:url => '/assets/:style-:filename'
},
'staging' => {
:storage => :s3,
:s3_credentials => {
:access_key_id => ENV['AWS_KEY_ID'],
:secret_access_key => ENV['AWS_KEY_SECRET'],
:s3_host_name => 's3-us-west-1.amazonaws.com'
},
:path => '/assets/:style-:filename',
:bucket => ENV['AWS_IMPORT_BUCKET'],
:url => ':s3_path_url'
},
'production' => {
:storage => :s3,
:s3_credentials => {
:access_key_id => ENV['AWS_KEY_ID'],
:secret_access_key => ENV['AWS_KEY_SECRET'],
:s3_host_name => 's3-us-west-1.amazonaws.com'
},
:path => '/assets/:style-:filename',
:bucket => ENV['AWS_IMPORT_BUCKET'],
:url => ':s3_path_url'
},
'test' => {
:path => ':rails_root/tmp/import/test/assets/processed/:style-:filename',
:url => '/assets/:style-:filename'
}
}
has_mongoid_attached_file :asset, {
:styles => {
:jpg => ["", :jpg]
},
:convert_options => {
:jpg => "-quality 90"
}
}.merge(PAPERCLIP_SETTINGS[Rails.env])
def catalog
Catalog.where(key: catalog_key).first
end
def self.assets_for_catalog(key)
{}.tap do |hash|
Asset.where(catalog_key: key).order([[:position, :asc]]).each do |a|
if a.category
hash[a.type.pluralize] ||= {}
hash[a.type.pluralize][a.category] ||= []
hash[a.type.pluralize][a.category] << a.asset.url(:jpg)
else
hash[a.type.pluralize] ||= []
hash[a.type.pluralize] << a.asset.url(:jpg)
end
end
end
end
end
Fabricator :asset do
original_filename 'SP15R_Accessories_L.png'
catalog_key 'SP15R'
type 'category_page'
category 'Accessories'
position '0'
end
require 'rails_helper'
describe Asset do
it 'has a valid fabrication' do
assert true
# Fabricate(:asset).should be_valid
end
# it 'is associated with a catalog'
# it 'has a valid original filename'
# it 'has a type'
# it 'can call for assets based on catalog key'
end
rspec spec/testing_stuff_spec.rb
/Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/spec/raise_trouble.rb:1:in `<top (required)>': Ohhh myyyy (RuntimeError)
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/integrations/base.rb:24:in `const_defined?'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/integrations/base.rb:24:in `available?'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/initializers/rails.rb:5:in `block in <top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/initializers/rails.rb:4:in `each'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/initializers/rails.rb:4:in `<top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/initializers.rb:3:in `block in <top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/initializers.rb:2:in `each'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/initializers.rb:2:in `<top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine/core.rb:12:in `<top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bundler/gems/state_machine-88e45a1b1622/lib/state_machine.rb:7:in `<top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/robin/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in `each'
from /Users/robin/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in `block in require'
from /Users/robin/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `each'
from /Users/robin/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `require'
from /Users/robin/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler.rb:131:in `require'
from /Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/config/application.rb:11:in `<top (required)>'
from /Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/config/environment.rb:2:in `require'
from /Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/config/environment.rb:2:in `<top (required)>'
from /Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/spec/rails_helper.rb:4:in `require'
from /Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/spec/rails_helper.rb:4:in `<top (required)>'
from /Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/spec/testing_stuff_spec.rb:1:in `require'
from /Users/robin/dev/Elastic_Suite/skillet_fork/oneskillet/spec/testing_stuff_spec.rb:1:in `<top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `load'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `block in load_spec_files'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `each'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `load_spec_files'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:97:in `setup'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:in `run'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in `run'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.2/exe/rspec:4:in `<top (required)>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/rspec:23:in `load'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/rspec:23:in `<main>'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/ruby_executable_hooks:15:in `eval'
from /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/ruby_executable_hooks:15:in `<main>'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'fabrication'
require 'rspec/rails'
require 'rails/mongoid'
require 'capybara/rspec'
require 'database_cleaner'
require 'spec_helper'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.order = "random"
config.infer_spec_type_from_file_location!
config.before(:suite) do
# DatabaseCleaner[:mongoid].strategy = :truncation
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner[:mongoid].strategy = :truncation
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.after(:suite) do
Fabrication.clear_definitions
end
end
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
expectations.syntax = :expect
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
end
Asset
has a valid fabrication (FAILED - 1)
Failures:
1) Asset has a valid fabrication
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activerecord-4.1.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activerecord-4.1.1/lib/active_record/connection_handling.rb:87:in `connection'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activerecord-4.1.1/lib/active_record/fixtures.rb:499:in `create_fixtures'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activerecord-4.1.1/lib/active_record/fixtures.rb:984:in `load_fixtures'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activerecord-4.1.1/lib/active_record/fixtures.rb:957:in `setup_fixtures'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/activerecord-4.1.1/lib/active_record/fixtures.rb:806:in `before_setup'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:67:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:294:in `instance_exec'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:294:in `instance_exec'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:210:in `call'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/hooks.rb:432:in `run'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/hooks.rb:485:in `run'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:303:in `with_around_example_hooks'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:145:in `run'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:494:in `block in run_examples'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:490:in `map'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:490:in `run_examples'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:457:in `run'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:112:in `map'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/reporter.rb:54:in `report'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:108:in `run_specs'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:86:in `run'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:70:in `run'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:38:in `invoke'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/gems/rspec-core-3.0.1/exe/rspec:4:in `<top (required)>'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/rspec:23:in `load'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/rspec:23:in `<main>'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/ruby_executable_hooks:15:in `eval'
# /Users/robin/.rvm/gems/ruby-2.1.0@skillet/bin/ruby_executable_hooks:15:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
Finished in 0.0779 seconds (files took 11.43 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/models/asset_spec.rb:4 # Asset has a valid fabrication
Top 1 slowest examples (0.00216 seconds, 2.8% of total time):
Asset has a valid fabrication
0.00216 seconds ./spec/models/asset_spec.rb:4
Randomized with seed 8157
# FYI : The test is "assert true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment