Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Forgot to ignore some temporary test data #3

Merged
5 commits merged into from

2 participants

@gzigzigzeo

Added gitignore and removed spec/tmp from tree

@y8
Collaborator
y8 commented

А с каким из реквестов мереджить то?

@gzigzigzeo

По-моему, это не важно. Он с моей репой мерджит, а не с реквестом. Если нет - скажи, я сделаю еще раз. Еще надо Railtie с инициализатором добавить, а то сейчас если эту штуку до пейперклипа загрузить - он валится с ошибкой. Позже займусь.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 25, 2010
  1. @gzigzigzeo

    Fixed wrong alias statement

    gzigzigzeo authored
  2. @gzigzigzeo
  3. @gzigzigzeo

    forgot about tempfiles

    gzigzigzeo authored
  4. @gzigzigzeo

    Add tempfiles to gitignore

    gzigzigzeo authored
  5. @gzigzigzeo

    gitignore

    gzigzigzeo authored
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -0,0 +1,2 @@
+spec/tmp/*/**
+pkg
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--backtrace
View
12 Gemfile
@@ -0,0 +1,12 @@
+source "http://rubygems.org"
+
+gem "activerecord", ">= 3", :require => "active_record"
+gem "sqlite3-ruby", :require => "sqlite3"
+gem "paperclip", :require => "paperclip"
+gem "paperclip-meta", :path => '.'
+
+if RUBY_VERSION < '1.9'
+ gem "ruby-debug", ">= 0.10.3"
+end
+
+gem "rspec"
View
54 Gemfile.lock
@@ -0,0 +1,54 @@
+PATH
+ remote: .
+ specs:
+ paperclip-meta (0.1)
+ paperclip
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activesupport (3.0.3)
+ arel (2.0.4)
+ builder (2.1.2)
+ columnize (0.3.2)
+ diff-lcs (1.1.2)
+ i18n (0.4.2)
+ linecache (0.43)
+ paperclip (2.3.6)
+ activerecord
+ activesupport
+ rspec (2.1.0)
+ rspec-core (~> 2.1.0)
+ rspec-expectations (~> 2.1.0)
+ rspec-mocks (~> 2.1.0)
+ rspec-core (2.1.0)
+ rspec-expectations (2.1.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.1.0)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ sqlite3-ruby (1.3.2)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (>= 3)
+ paperclip
+ paperclip-meta!
+ rspec
+ ruby-debug (>= 0.10.3)
+ sqlite3-ruby
View
34 Rakefile
@@ -1,8 +1,34 @@
require 'rake'
require 'rake/testtask'
-require 'rake/rdoctask'
+require 'rspec/core'
+require 'rspec/core/rake_task'
-desc "Build the gem into the current directory"
-task :gem => :gemspec do
- `gem build #{spec.name}.gemspec`
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
+
+begin
+ include_files = ["README*", "LICENSE", "Rakefile", "init.rb", "{lib,test}/**/*"].map do |glob|
+ Dir[glob]
+ end.flatten
+
+ require "jeweler"
+ Jeweler::Tasks.new do |s|
+ s.name = "paperclip-meta"
+ s.version = "0.1"
+ s.author = "Alexey Bondar"
+ s.email = "y8@ya.ru"
+ s.homepage = "http://github.com/y8/paperclip-meta"
+ s.description = "Add width, height and size methods to paperclip thumbnails"
+ s.summary = "Thumbnail dimensions for paperclip"
+ s.platform = Gem::Platform::RUBY
+ s.files = include_files
+ s.require_path = "lib"
+ s.rubyforge_project = "paperclip-meta"
+ s.has_rdoc = false
+ s.add_dependency 'paperclip'
+ end
+
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
View
21 lib/paperclip-meta.rb
@@ -1,7 +1,16 @@
module Paperclip
class Attachment
- alias original_post_process_styles post_process_styles
+ alias :original_post_process_styles :post_process_styles
+ alias :original_save :save
+ # If attachment deleted - destroy meta data
+ def save
+ unless @queued_for_delete.empty?
+ instance_write(:meta, ActiveSupport::Base64.encode64(Marshal.dump({}))) if instance.respond_to?(:"#{name}_meta=")
+ end
+ original_save
+ end
+
# If model has #{name}_meta column we getting sizes of processed
# thumbnails and saving it to #{name}_meta column.
def post_process_styles
@@ -11,8 +20,12 @@ def post_process_styles
meta = {}
@queued_for_write.each do |style, file|
- geo = Geometry.from_file file
- meta[style] = {:width => geo.width.to_i, :height => geo.height.to_i, :size => File.size(file) }
+ begin
+ geo = Geometry.from_file file
+ meta[style] = {:width => geo.width.to_i, :height => geo.height.to_i, :size => File.size(file) }
+ rescue NotIdentifiedByImageMagickError => e
+ meta[style] = {}
+ end
end
instance_write(:meta, ActiveSupport::Base64.encode64(Marshal.dump(meta)))
@@ -38,6 +51,6 @@ def meta_read(style, item)
meta.key?(style) ? meta[style][item] : nil
end
end
- end
+ end
end
end
View
66 paperclip-meta.gemspec
@@ -1,19 +1,49 @@
-include_files = ["README*", "LICENSE", "Rakefile", "init.rb", "{lib,test}/**/*"].map do |glob|
- Dir[glob]
-end.flatten
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{paperclip-meta}
+ s.version = "0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Alexey Bondar"]
+ s.date = %q{2010-11-25}
+ s.description = %q{Add width, height and size methods to paperclip thumbnails}
+ s.email = %q{y8@ya.ru}
+ s.extra_rdoc_files = [
+ "README.rdoc"
+ ]
+ s.files = [
+ "README.rdoc",
+ "Rakefile",
+ "init.rb",
+ "lib/paperclip-meta.rb"
+ ]
+ s.homepage = %q{http://github.com/y8/paperclip-meta}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{paperclip-meta}
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Thumbnail dimensions for paperclip}
+ s.test_files = [
+ "spec/paperclip-meta/paperclip-meta_spec.rb",
+ "spec/schema.rb",
+ "spec/spec_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<paperclip>, [">= 0"])
+ else
+ s.add_dependency(%q<paperclip>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<paperclip>, [">= 0"])
+ end
+end
-spec = Gem::Specification.new do |s|
- s.name = "paperclip-meta"
- s.version = "0.1"
- s.author = "Alexey Bondar"
- s.email = "y8@ya.ru"
- s.homepage = "http://github.com/y8/paperclip-meta"
- s.description = "Add width, height and size methods to paperclip thumbnails"
- s.summary = "Thumbnail dimensions for paperclip"
- s.platform = Gem::Platform::RUBY
- s.files = include_files
- s.require_path = "lib"
- s.rubyforge_project = "paperclip-meta"
- s.has_rdoc = false
- s.add_dependency 'paperclip'
-end
View
BIN  spec/fixtures/big.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  spec/fixtures/big.zip
Binary file not shown
View
BIN  spec/fixtures/small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
56 spec/paperclip-meta/paperclip-meta_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe "Geometry saver plugin" do
+ before(:each) do
+ small_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'small.png')
+ big_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'big.jpg')
+ not_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'big.zip')
+ @big_image = File.open(big_path)
+ @small_image = File.open(small_path)
+ @big_size = Paperclip::Geometry.from_file(big_path)
+ @small_size = Paperclip::Geometry.from_file(small_path)
+ @not_image = File.open(not_path)
+ end
+
+ it "saves image geometry for original image" do
+ img = Image.new
+ img.small_image = @small_image
+ img.save!
+
+ img.reload # Ensure that updates really saved to db
+
+ img.small_image.width eq(@small_size.width)
+ img.small_image.height eq(@small_size.height)
+ end
+
+ it "saves geometry for styles" do
+ img = Image.new
+ img.small_image = @small_image
+ img.big_image = @big_image
+ img.save!
+
+ img.big_image.width(:small).should == 100
+ img.big_image.height(:small).should == 100
+ end
+
+ it "clears geometry fields when image is destroyed" do
+ img = Image.new
+ img.small_image = @small_image
+ img.big_image = @big_image
+ img.save!
+
+ img.big_image.width(:small).should == 100
+
+ img.big_image = nil
+ img.save!
+
+ img.big_image.width(:small).should be_nil
+ end
+
+ it "does not fails when file is not an image" do
+ img = Image.new
+ img.small_image = @not_image
+ lambda { img.save! }.should_not raise_error
+ img.small_image.width(:small).should be_nil
+ end
+end
View
15 spec/schema.rb
@@ -0,0 +1,15 @@
+ActiveRecord::Schema.define :version => 0 do
+ create_table "images", :force => true do |t|
+ t.string :small_image_file_name
+ t.string :small_image_content_type
+ t.integer :small_image_updated_at
+ t.integer :small_image_file_size
+ t.string :small_image_meta
+
+ t.string :big_image_file_name
+ t.string :big_image_content_type
+ t.integer :big_image_updated_at
+ t.integer :big_image_file_size
+ t.string :big_image_meta
+ end
+end
View
36 spec/spec_helper.rb
@@ -0,0 +1,36 @@
+$LOAD_PATH << "." unless $LOAD_PATH.include?(".")
+
+begin
+ require "bundler"
+ Bundler.setup
+rescue Bundler::GemNotFound
+ raise RuntimeError, "Bundler couldn't find some gems." +
+ "Did you run `bundle install`?"
+end
+
+Bundler.require
+require 'logger'
+Paperclip::Railtie.insert
+
+ActiveRecord::Base.establish_connection(
+ "adapter" => "sqlite3",
+ "database" => ":memory:"
+)
+
+ActiveRecord::Base.logger = Logger.new(nil)
+
+load(File.dirname(__FILE__) + '/schema.rb')
+$: << File.join(File.dirname(__FILE__), '..', 'lib')
+
+class Image < ActiveRecord::Base
+ has_attached_file :small_image,
+ :storage => :filesystem,
+ :path => "./spec/tmp/:style/:id.:extension",
+ :url => "./spec/tmp/:style/:id.extension"
+
+ has_attached_file :big_image,
+ :storage => :filesystem,
+ :path => "./spec/tmp/fixtures/tmp/:style/:id.:extension",
+ :url => "./spec/tmp/fixtures/tmp/:style/:id.extension",
+ :styles => { :small => "100x100#" }
+end
Something went wrong with that request. Please try again.