Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit

  • Loading branch information...
commit 61864f2b8c486b9b819ed0eb006620b6c6e37d7c 0 parents
@reu reu authored
5 .gitignore
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+db/*
6 Gemfile
@@ -0,0 +1,6 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in carrierwave_neo4j.gemspec
+gemspec
+
+gem "ruby-debug"
1  Rakefile
@@ -0,0 +1 @@
+require 'bundler/gem_tasks'
25 carrierwave-neo4j.gemspec
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "carrierwave/neo4j/version"
+
+Gem::Specification.new do |s|
+ s.name = "carrierwave-neo4j"
+ s.version = CarrierWave::Neo4j::VERSION
+ s.platform = "java"
+ s.authors = ["Rodrigo Navarro"]
+ s.email = ["navarro@manapot.com.br"]
+ s.homepage = ""
+ s.summary = %q{Neo4j support for Carrierwave}
+ s.description = %q{Neo4j support for Carrierwave}
+
+ s.rubyforge_project = "carrierwave_neo4j"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency("neo4j", "~> 1.1")
+ s.add_dependency("carrierwave", "~> 0.5")
+ s.add_development_dependency("rspec", "~> 2.0")
+end
34 lib/carrierwave/neo4j.rb
@@ -0,0 +1,34 @@
+require "carrierwave/neo4j/version"
+require "neo4j"
+require "carrierwave"
+
+module CarrierWave
+ module Neo4j
+ include CarrierWave::Mount
+
+ ##
+ # See +CarrierWave::Mount#mount_uploader+ for documentation
+ #
+ def mount_uploader(column, uploader = nil, options = {}, &block)
+ property column
+
+ super
+
+ alias_method :read_uploader, :read_attribute
+ alias_method :write_uploader, :write_attribute
+
+ after_save :"store_#{column}!"
+ before_save :"write_#{column}_identifier"
+ after_destroy :"remove_#{column}!"
+
+ class_eval <<-RUBY, __FILE__, __LINE__+1
+ def _mounter(column)
+ @_mounters ||= {}
+ @_mounters[column] ||= CarrierWave::Mount::Mounter.new(self, column)
+ end
+ RUBY
+ end
+ end
+end
+
+Neo4j::Rails::Model.extend CarrierWave::Neo4j
5 lib/carrierwave/neo4j/version.rb
@@ -0,0 +1,5 @@
+module CarrierWave
+ module Neo4j
+ VERSION = "0.0.1"
+ end
+end
BIN  spec/fixtures/tarja.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 spec/neo4j_spec.rb
@@ -0,0 +1,90 @@
+require "spec_helper"
+
+def reset_class(uploader = DefaultUploader)
+ class_name = "User"
+ Object.send(:remove_const, class_name) rescue nil
+ user_class = Object.const_set(class_name, Class.new(Neo4j::Rails::Model))
+
+ user_class.class_eval do
+ mount_uploader :image, uploader
+ end
+
+ user_class
+end
+
+class DefaultUploader < CarrierWave::Uploader::Base; end
+
+describe CarrierWave::Neo4j do
+ let(:user_class) { reset_class }
+ let(:user) { user_class.new }
+
+ after do
+ User.destroy_all
+ end
+
+ describe "#image" do
+ let(:record) { user_class.new }
+ subject { record.image }
+
+ context "when nothing is assigned" do
+ it { should be_blank }
+ end
+
+ context "when an empty string is assigned" do
+ before do
+ record.image = ""
+ record.save
+ record.reload
+ end
+
+ it { should be_blank }
+ end
+
+ context "when a filename is stored" do
+ before do
+ record.image = File.open(file_path("tarja.jpg"))
+ record.save
+ record.reload
+ end
+
+ it { should be_an_instance_of DefaultUploader }
+ its(:current_path) { should == public_path("uploads/tarja.jpg") }
+ end
+ end
+
+ describe "#save" do
+ context "when remove_image? is true" do
+ let(:record) { user_class.new }
+
+ before do
+ Neo4j::Transaction.run do
+ record.image = File.open(file_path("tarja.jpg"))
+ record.save
+
+ record.remove_image = true
+ record.save # Getting NotInTransactionException here if not wrapped in a transaction block, maybe Neo4j bug?
+ record.reload
+ end
+ end
+
+ subject { record }
+
+ its(:image) { should be_blank }
+ end
+ end
+
+ describe "#destroy" do
+ let(:record) { user_class.new }
+
+ before do
+ record.image = File.open(file_path("tarja.jpg"))
+ record.save
+ end
+
+ it "also destroys the image" do
+ expect { record.destroy }.to change {
+ File.exist? public_path("uploads/tarja.jpg")
+ }.from(true).to(false)
+ end
+ end
+end
16 spec/spec_helper.rb
@@ -0,0 +1,16 @@
+require "rubygems"
+require "bundler/setup"
+require "rspec"
+
+require "carrierwave"
+require "carrierwave/neo4j"
+
+def file_path(*paths)
+ File.expand_path(File.join(File.dirname(__FILE__), "fixtures", *paths))
+end
+
+def public_path(*paths)
+ File.expand_path(File.join(File.dirname(__FILE__), "public", *paths))
+end
+
+CarrierWave.root = public_path
Please sign in to comment.
Something went wrong with that request. Please try again.