diff --git a/.gitignore b/.gitignore index f2901c91..3eb387a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.gem +.bundle +Gemfile.lock +pkg/* couch_potato_js_runner.js -pkg -.rvmrc diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 00000000..e1945149 --- /dev/null +++ b/.rvmrc @@ -0,0 +1 @@ +rvm 1.9.2@couch_potato diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..fb8608db --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in couch_potato.gemspec +gemspec diff --git a/Rakefile b/Rakefile index 013f33ed..bdd627e9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,8 @@ +require 'bundler' +Bundler::GemHelper.install_tasks + require 'rake' -require 'spec/rake/spectask' +require "rspec/core/rake_task" require 'rake/rdoctask' def with_validatable(&block) @@ -45,15 +48,15 @@ task :spec_unit_active_model do end desc "Run functional specs with default validation framework, override with VALIDATION_FRAMEWORK" -Spec::Rake::SpecTask.new(:spec_functional_default) do |t| - t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] - t.spec_files = FileList['spec/*_spec.rb'] +RSpec::Core::RakeTask.new(:spec_functional_default) do |spec| + spec.pattern = 'spec/*_spec.rb' + spec.rspec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] end desc "Run unit specs with default validation framework, override with VALIDATION_FRAMEWORK" -Spec::Rake::SpecTask.new(:spec_unit_default) do |t| - t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] - t.spec_files = FileList['spec/unit/*_spec.rb'] +RSpec::Core::RakeTask.new(:spec_unit_default) do |spec| + spec.pattern = 'spec/unit/*_spec.rb' + spec.rspec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] end desc "Run functional specs with all validation frameworks" @@ -77,22 +80,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/couch_potato.rb') rdoc.rdoc_files.include('lib/couch_potato/**/*.rb') end - - -begin - require 'jeweler' - Jeweler::Tasks.new do |s| - s.name = "couch_potato" - s.summary = %Q{Ruby persistence layer for CouchDB} - s.email = "alex@upstream-berlin.com" - s.homepage = "http://github.com/langalex/couch_potato" - s.description = "Ruby persistence layer for CouchDB" - s.authors = ["Alexander Lang"] - s.files = FileList["[A-Z]*.*", "{lib,spec,rails}/**/*", "init.rb"] - s.add_dependency 'json' - s.add_dependency 'couchrest', '>=1.0.1' - s.add_dependency 'activemodel' - end -rescue LoadError - puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" -end diff --git a/VERSION.yml b/VERSION.yml deleted file mode 100644 index 9623d366..00000000 --- a/VERSION.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -:major: 0 -:minor: 4 -:patch: 0 -:build: diff --git a/couch_potato.gemspec b/couch_potato.gemspec index 1bb8272a..b151989f 100644 --- a/couch_potato.gemspec +++ b/couch_potato.gemspec @@ -1,163 +1,25 @@ -# Generated by jeweler -# DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command # -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "couch_potato/version" Gem::Specification.new do |s| - s.name = %q{couch_potato} - s.version = "0.4.0" - - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.name = "couch_potato" + s.summary = %Q{Ruby persistence layer for CouchDB} + s.email = "alex@upstre.am" + s.homepage = "http://github.com/langalex/couch_potato" + s.description = "Ruby persistence layer for CouchDB" s.authors = ["Alexander Lang"] - s.date = %q{2010-12-10} - s.description = %q{Ruby persistence layer for CouchDB} - s.email = %q{alex@upstream-berlin.com} - s.extra_rdoc_files = [ - "README.md" - ] - s.files = [ - "CHANGES.md", - "MIT-LICENSE.txt", - "README.md", - "VERSION.yml", - "init.rb", - "lib/core_ext/date.rb", - "lib/core_ext/object.rb", - "lib/core_ext/string.rb", - "lib/core_ext/symbol.rb", - "lib/core_ext/time.rb", - "lib/couch_potato.rb", - "lib/couch_potato/database.rb", - "lib/couch_potato/persistence.rb", - "lib/couch_potato/persistence/active_model_compliance.rb", - "lib/couch_potato/persistence/attachments.rb", - "lib/couch_potato/persistence/callbacks.rb", - "lib/couch_potato/persistence/dirty_attributes.rb", - "lib/couch_potato/persistence/ghost_attributes.rb", - "lib/couch_potato/persistence/json.rb", - "lib/couch_potato/persistence/magic_timestamps.rb", - "lib/couch_potato/persistence/properties.rb", - "lib/couch_potato/persistence/simple_property.rb", - "lib/couch_potato/persistence/type_caster.rb", - "lib/couch_potato/railtie.rb", - "lib/couch_potato/rspec.rb", - "lib/couch_potato/rspec/matchers.rb", - "lib/couch_potato/rspec/matchers/json2.js", - "lib/couch_potato/rspec/matchers/list_as_matcher.rb", - "lib/couch_potato/rspec/matchers/map_to_matcher.rb", - "lib/couch_potato/rspec/matchers/print_r.js", - "lib/couch_potato/rspec/matchers/reduce_to_matcher.rb", - "lib/couch_potato/rspec/stub_db.rb", - "lib/couch_potato/validation.rb", - "lib/couch_potato/validation/with_active_model.rb", - "lib/couch_potato/validation/with_validatable.rb", - "lib/couch_potato/view/base_view_spec.rb", - "lib/couch_potato/view/custom_view_spec.rb", - "lib/couch_potato/view/custom_views.rb", - "lib/couch_potato/view/lists.rb", - "lib/couch_potato/view/model_view_spec.rb", - "lib/couch_potato/view/properties_view_spec.rb", - "lib/couch_potato/view/raw_view_spec.rb", - "lib/couch_potato/view/view_query.rb", - "rails/init.rb", - "rails/reload_classes.rb", - "spec/attachments_spec.rb", - "spec/callbacks_spec.rb", - "spec/create_spec.rb", - "spec/custom_view_spec.rb", - "spec/default_property_spec.rb", - "spec/destroy_spec.rb", - "spec/fixtures/address.rb", - "spec/fixtures/person.rb", - "spec/property_spec.rb", - "spec/rails_spec.rb", - "spec/railtie_spec.rb", - "spec/spec.opts", - "spec/spec_helper.rb", - "spec/unit/active_model_compliance_spec.rb", - "spec/unit/attributes_spec.rb", - "spec/unit/base_view_spec_spec.rb", - "spec/unit/callbacks_spec.rb", - "spec/unit/couch_potato_spec.rb", - "spec/unit/create_spec.rb", - "spec/unit/custom_views_spec.rb", - "spec/unit/database_spec.rb", - "spec/unit/date_spec.rb", - "spec/unit/dirty_attributes_spec.rb", - "spec/unit/initialize_spec.rb", - "spec/unit/json_create_id_spec.rb", - "spec/unit/lists_spec.rb", - "spec/unit/model_view_spec_spec.rb", - "spec/unit/properties_view_spec_spec.rb", - "spec/unit/rspec_matchers_spec.rb", - "spec/unit/rspec_stub_db_spec.rb", - "spec/unit/string_spec.rb", - "spec/unit/time_spec.rb", - "spec/unit/validation_spec.rb", - "spec/unit/view_query_spec.rb", - "spec/update_spec.rb", - "spec/view_updates_spec.rb" - ] - s.homepage = %q{http://github.com/langalex/couch_potato} - s.rdoc_options = ["--charset=UTF-8"] + s.version = CouchPotato::VERSION + s.platform = Gem::Platform::RUBY + + s.add_dependency 'json' + s.add_dependency 'couchrest', '>=1.0.1' + s.add_dependency 'activemodel' + + s.add_development_dependency 'rspec', '>=2.0' + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} - s.summary = %q{Ruby persistence layer for CouchDB} - s.test_files = [ - "spec/attachments_spec.rb", - "spec/callbacks_spec.rb", - "spec/create_spec.rb", - "spec/custom_view_spec.rb", - "spec/default_property_spec.rb", - "spec/destroy_spec.rb", - "spec/fixtures/address.rb", - "spec/fixtures/person.rb", - "spec/property_spec.rb", - "spec/rails_spec.rb", - "spec/railtie_spec.rb", - "spec/spec_helper.rb", - "spec/unit/active_model_compliance_spec.rb", - "spec/unit/attributes_spec.rb", - "spec/unit/base_view_spec_spec.rb", - "spec/unit/callbacks_spec.rb", - "spec/unit/couch_potato_spec.rb", - "spec/unit/create_spec.rb", - "spec/unit/custom_views_spec.rb", - "spec/unit/database_spec.rb", - "spec/unit/date_spec.rb", - "spec/unit/dirty_attributes_spec.rb", - "spec/unit/initialize_spec.rb", - "spec/unit/json_create_id_spec.rb", - "spec/unit/lists_spec.rb", - "spec/unit/model_view_spec_spec.rb", - "spec/unit/properties_view_spec_spec.rb", - "spec/unit/rspec_matchers_spec.rb", - "spec/unit/rspec_stub_db_spec.rb", - "spec/unit/string_spec.rb", - "spec/unit/time_spec.rb", - "spec/unit/validation_spec.rb", - "spec/unit/view_query_spec.rb", - "spec/update_spec.rb", - "spec/view_updates_spec.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, [">= 0"]) - s.add_runtime_dependency(%q, [">= 1.0.1"]) - s.add_runtime_dependency(%q, [">= 0"]) - else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 1.0.1"]) - s.add_dependency(%q, [">= 0"]) - end - else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 1.0.1"]) - s.add_dependency(%q, [">= 0"]) - end end - diff --git a/lib/couch_potato.rb b/lib/couch_potato.rb index 6285b84c..9d7997ac 100644 --- a/lib/couch_potato.rb +++ b/lib/couch_potato.rb @@ -7,30 +7,28 @@ JSON.create_id = 'ruby_class' -unless defined?(CouchPotato) - module CouchPotato - Config = Struct.new(:database_name, :validation_framework).new - Config.validation_framework = :active_model - - # Returns a database instance which you can then use to create objects and query views. You have to set the CouchPotato::Config.database_name before this works. - def self.database - @@__database ||= Database.new(self.couchrest_database) - end +module CouchPotato + Config = Struct.new(:database_name, :validation_framework).new + Config.validation_framework = :active_model - # Returns the underlying CouchRest database object if you want low level access to your CouchDB. You have to set the CouchPotato::Config.database_name before this works. - def self.couchrest_database - @@__couchrest_database ||= CouchRest.database(full_url_to_database) - end + # Returns a database instance which you can then use to create objects and query views. You have to set the CouchPotato::Config.database_name before this works. + def self.database + @@__database ||= Database.new(self.couchrest_database) + end + + # Returns the underlying CouchRest database object if you want low level access to your CouchDB. You have to set the CouchPotato::Config.database_name before this works. + def self.couchrest_database + @@__couchrest_database ||= CouchRest.database(full_url_to_database) + end - private + private - def self.full_url_to_database - raise('No Database configured. Set CouchPotato::Config.database_name') unless CouchPotato::Config.database_name - if CouchPotato::Config.database_name.match(%r{https?://}) - CouchPotato::Config.database_name - else - "http://127.0.0.1:5984/#{CouchPotato::Config.database_name}" - end + def self.full_url_to_database + raise('No Database configured. Set CouchPotato::Config.database_name') unless CouchPotato::Config.database_name + if CouchPotato::Config.database_name.match(%r{https?://}) + CouchPotato::Config.database_name + else + "http://127.0.0.1:5984/#{CouchPotato::Config.database_name}" end end end diff --git a/lib/couch_potato/rspec/matchers.rb b/lib/couch_potato/rspec/matchers.rb index 1e0effc2..71bdf1ac 100644 --- a/lib/couch_potato/rspec/matchers.rb +++ b/lib/couch_potato/rspec/matchers.rb @@ -17,7 +17,7 @@ def run_js(js) require 'couch_potato/rspec/matchers/reduce_to_matcher' require 'couch_potato/rspec/matchers/list_as_matcher' -module Spec +module RSpec module Matchers def map(document) CouchPotato::RSpec::MapToProxy.new(document) diff --git a/lib/couch_potato/rspec/stub_db.rb b/lib/couch_potato/rspec/stub_db.rb index 8cffc787..1888d426 100644 --- a/lib/couch_potato/rspec/stub_db.rb +++ b/lib/couch_potato/rspec/stub_db.rb @@ -14,7 +14,7 @@ def with(*args) end def and_return(return_value) - view_stub = Spec::Mocks::Mock.new("#{@clazz}.#{@view}(#{@args.try(:join, ', ')}) view") + view_stub = RSpec::Mocks::Mock.new("#{@clazz}.#{@view}(#{@args.try(:join, ', ')}) view") _stub = @clazz.stub(@view) _stub.with(*@args) if @args _stub.and_return(view_stub) @@ -37,7 +37,7 @@ def stub_db(options = {}) end end -module Spec +module RSpec module Mocks module ExampleMethods include CouchPotato::RSpec::StubDb diff --git a/lib/couch_potato/version.rb b/lib/couch_potato/version.rb new file mode 100644 index 00000000..2753a958 --- /dev/null +++ b/lib/couch_potato/version.rb @@ -0,0 +1,3 @@ +module CouchPotato + VERSION = "0.4.0" +end diff --git a/spec/create_spec.rb b/spec/create_spec.rb index 1a8be41e..3d1495b7 100644 --- a/spec/create_spec.rb +++ b/spec/create_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe "create" do - before(:all) do + before(:each) do recreate_db end describe "succeeds" do @@ -23,6 +23,7 @@ CouchPotato.couchrest_database.get(@comment.id).updated_at.should == Time.parse('2010-01-02 12:34:48 +0000') end end + describe "fails" do it "should not store anything" do @comment = Comment.new diff --git a/spec/railtie_spec.rb b/spec/railtie_spec.rb index 9b677896..8c3fdee6 100644 --- a/spec/railtie_spec.rb +++ b/spec/railtie_spec.rb @@ -10,7 +10,7 @@ def self.initializer(*args) end def self.root - Spec::Mocks::Mock.new :join => '' + RSpec::Mocks::Mock.new :join => '' end end diff --git a/spec/spec.opts b/spec/spec.opts index ad561bd2..89da67b6 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -1,4 +1,2 @@ --colour --format progress ---loadby mtime ---reverse \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7ee9d837..35a0c69f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ require 'rubygems' -require 'spec' +require 'rspec' require 'time' $:.unshift(File.dirname(__FILE__) + '/../lib') @@ -41,7 +41,7 @@ def recreate_db end recreate_db -Spec::Matchers.define :string_matching do |regex| +RSpec::Matchers.define :string_matching do |regex| match do |string| string =~ regex end diff --git a/spec/unit/database_spec.rb b/spec/unit/database_spec.rb index c903eb46..edff2b21 100644 --- a/spec/unit/database_spec.rb +++ b/spec/unit/database_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' class DbTestUser + include CouchPotato::Persistence end # namespaced model @@ -52,7 +53,7 @@ class Child end it "should set itself on the model" do - user = mock 'user' + user = mock('user').as_null_object DbTestUser.stub!(:new).and_return(user) db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => DbTestUser.json_create({JSON.create_id => 'DbTestUser'}))) user.should_receive(:database=).with(db) diff --git a/spec/unit/rspec_stub_db_spec.rb b/spec/unit/rspec_stub_db_spec.rb index 00b805cf..35f14a4a 100644 --- a/spec/unit/rspec_stub_db_spec.rb +++ b/spec/unit/rspec_stub_db_spec.rb @@ -10,7 +10,7 @@ class WithStubbedView describe "stubbing the db" do it "should replace CouchPotato.database with a stub" do stub_db - CouchPotato.database.should be_a(Spec::Mocks::Mock) + CouchPotato.database.should be_a(RSpec::Mocks::Mock) end it "should return the stub" do @@ -26,7 +26,7 @@ class WithStubbedView end it "should stub the view to return a stub" do - WithStubbedView.stubbed_view('123').should be_a(Spec::Mocks::Mock) + WithStubbedView.stubbed_view('123').should be_a(RSpec::Mocks::Mock) end it "should stub the database to return fake results when called with the stub" do