-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first working example, but only for creating
- Loading branch information
0 parents
commit e51f76b
Showing
12 changed files
with
552 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Stuffing | ||
======== | ||
|
||
Introduction goes here. | ||
|
||
|
||
Example | ||
======= | ||
|
||
Example goes here. | ||
|
||
|
||
Copyright (c) 2009 [name of plugin creator], released under the MIT license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rake' | ||
require 'spec/rake/spectask' | ||
|
||
desc 'Default: run specs.' | ||
task :default => :spec | ||
|
||
desc 'Run the specs' | ||
Spec::Rake::SpecTask.new(:spec) do |t| | ||
t.spec_opts = ['--colour --format progress --loadby mtime --reverse'] | ||
t.spec_files = FileList['spec/**/*_spec.rb'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$:.push(File.join(File.dirname(__FILE__), %w[.. .. rspec])) | ||
|
||
Autotest.add_discovery do | ||
"rspec" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'stuffing' | ||
ActiveRecord::Base.send(:include, Stuffing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Install hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'ostruct' | ||
require 'couchrest' | ||
module Stuffing | ||
def self.included(base) | ||
base.extend StuffingMethod | ||
end | ||
|
||
module StuffingMethod | ||
def stuffing(method_name = :stuffing, options = {}) | ||
|
||
after_create :create_stuffing | ||
after_update :update_stuffing | ||
after_destroy :destroy_stuffing | ||
|
||
class_eval do | ||
|
||
@@database = options[:database] || "#{File.basename(RAILS_ROOT)}_#{RAILS_ENV}" | ||
@@host = options[:host] || 'localhost' | ||
@@port = options[:port] || 5984 | ||
@@method_name = method_name | ||
|
||
def couchdb | ||
connection = CouchRest.new("http://#{@@host}:#{@@port}") | ||
connection.database!(@@database) | ||
end | ||
|
||
def couchdb_id | ||
"#{self.class}-#{id}" | ||
end | ||
|
||
define_method(method_name) do | ||
@stuffing ||= new_record? ? {} : couchdb.get(couchdb_id) | ||
end | ||
|
||
define_method("#{method_name}=") do |args| | ||
@stuffing = args | ||
end | ||
|
||
def create_stuffing | ||
couchdb.save({'_id' => couchdb_id}.merge(send(@@method_name))) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../spec/spec.opts |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
begin | ||
require File.dirname(__FILE__) + '/../../../../spec/spec_helper' | ||
rescue LoadError | ||
puts "You need to install rspec in your base app" | ||
exit | ||
end | ||
|
||
plugin_spec_dir = File.dirname(__FILE__) | ||
ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
|
||
class Booja < ActiveRecord::Base | ||
stuffing | ||
end | ||
|
||
describe do | ||
before do | ||
@booja = Booja.new | ||
@booja.couchdb.delete! | ||
end | ||
|
||
it "should have a default stuffing of an empty Hash" do | ||
@booja.stuffing.should == {} | ||
end | ||
|
||
it "should be able to set the stuffing" do | ||
@booja.stuffing = 'hello' | ||
@booja.stuffing.should == 'hello' | ||
end | ||
|
||
it "should give me the database" do | ||
@booja.couchdb.should be_a_kind_of(CouchRest::Database) | ||
end | ||
|
||
it "should give me the database" do | ||
@booja.couchdb.name.should == 'plugins_test' | ||
end | ||
|
||
it "should save the record to CouchDB" do | ||
@booja.save | ||
CouchRest.new('http://localhost:5984').database('plugins_test').get("Booja-#{@booja.id}").keys.should == ['_rev', '_id'] | ||
end | ||
|
||
describe "updating" do | ||
before do | ||
@booja = Booja.new | ||
@booja.couchdb.delete! | ||
@booja.stuffing = {:this => 'that'} | ||
@booja.save | ||
end | ||
|
||
it "should find the booja" do | ||
@found_booja = Booja.find(@booja.id) | ||
@found_booja.stuffing.keys.should == ['_id', '_rev', 'this'] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# desc "Explaining what the task does" | ||
# task :stuffing do | ||
# # Task goes here | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Uninstall hook code here |