Permalink
Browse files

Add first round of specs

  • Loading branch information...
1 parent a33093c commit 359b71adc3f4e5e3f6cedf6683ea86778f92c42a @JonathanTron JonathanTron committed Dec 29, 2012
View
@@ -0,0 +1,3 @@
+--color
+--format progress
+--backtrace
View
@@ -1,3 +1,5 @@
source "http://rubygems.org"
-gemspec
+gemspec
+
+gem "rspec-rails", require: false
View
@@ -8,7 +8,9 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- ZenTest (4.6.2)
+ actionmailer (3.2.9)
+ actionpack (= 3.2.9)
+ mail (~> 2.4.4)
actionpack (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
@@ -22,35 +24,59 @@ GEM
activemodel (3.2.9)
activesupport (= 3.2.9)
builder (~> 3.0.0)
+ activerecord (3.2.9)
+ activemodel (= 3.2.9)
+ activesupport (= 3.2.9)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.9)
+ activemodel (= 3.2.9)
+ activesupport (= 3.2.9)
activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
- autotest (4.4.6)
- ZenTest (>= 4.4.1)
+ arel (3.0.2)
builder (3.0.4)
+ combustion (0.3.3)
+ rails (>= 3.0.0)
+ thor (>= 0.14.6)
diff-lcs (1.1.3)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
json (1.7.5)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.19)
multi_json (1.4.0)
+ pg (0.14.1)
+ polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
+ rails (3.2.9)
+ actionmailer (= 3.2.9)
+ actionpack (= 3.2.9)
+ activerecord (= 3.2.9)
+ activeresource (= 3.2.9)
+ activesupport (= 3.2.9)
+ bundler (~> 1.0)
+ railties (= 3.2.9)
railties (3.2.9)
actionpack (= 3.2.9)
activesupport (= 3.2.9)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
- rake (0.8.7)
- rcov (0.9.11)
+ rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
rspec (2.7.0)
@@ -61,6 +87,11 @@ GEM
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
+ rspec-rails (2.7.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.7.0)
sequel (3.42.0)
sprockets (2.2.2)
hike (~> 1.2)
@@ -69,15 +100,17 @@ GEM
tilt (~> 1.1, != 1.3.0)
thor (0.16.0)
tilt (1.3.3)
- yard (0.7.3)
+ treetop (1.4.12)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.35)
PLATFORMS
ruby
DEPENDENCIES
- autotest (~> 4.4.6)
- rake (~> 0.8.7)
- rcov (~> 0.9.11)
- rspec (~> 2.7.0)
+ combustion (~> 0.3.1)
+ pg
+ rake (>= 0.8.7)
+ rspec-rails
talentbox-sequel-rails!
- yard (~> 0.5)
View
@@ -0,0 +1,7 @@
+require 'rubygems'
+require 'bundler'
+
+Bundler.require :default, :development
+
+Combustion.initialize!
+run Combustion::Application
View
@@ -1,7 +1,6 @@
-require 'sequel-rails/railtie'
-
module Rails
module Sequel
end
end
+require 'sequel-rails/railtie'
@@ -1,4 +1,3 @@
-require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/class/attribute_accessors'
module Rails
@@ -9,7 +8,7 @@ module Sequel
class Configuration
def self.for(root, database_yml_hash)
- Rails::Sequel.configuration ||= new(root, database_yml_hash)
+ ::Rails::Sequel.configuration ||= new(root, database_yml_hash)
end
attr_reader :root, :raw
@@ -1,20 +1,22 @@
-require 'sequel'
+require "sequel"
-require 'rails'
-require 'active_model/railtie'
+require "rails"
+require "active_model/railtie"
# Comment taken from active_record/railtie.rb
#
# For now, action_controller must always be present with
-# rails, so let's make sure that it gets required before
+# rails, so let"s make sure that it gets required before
# here. This is needed for correctly setting up the middleware.
# In the future, this might become an optional require.
-require 'action_controller/railtie'
-
-require 'sequel-rails/setup'
-require 'sequel-rails/railties/log_subscriber'
-require 'sequel-rails/railties/i18n_support'
+require "action_controller/railtie"
+require "sequel-rails/setup"
+require "sequel-rails/migrations"
+require "sequel-rails/railties/log_subscriber"
+require "sequel-rails/railties/i18n_support"
+require "sequel-rails/railties/controller_runtime"
+require "sequel/plugins/rails_extensions"
module Rails
module Sequel
@@ -37,24 +39,24 @@ class Railtie < Rails::Railtie
end
initializer 'sequel.configuration' do |app|
- configure_sequel(app)
+ configure_sequel app
end
initializer 'sequel.logger' do |app|
- setup_logger(app, Rails.logger)
+ setup_logger app, ::Rails.logger
end
initializer 'sequel.i18n_support' do |app|
- setup_i18n_support(app)
+ setup_i18n_support app
end
# Expose database runtime to controller for logging.
initializer 'sequel.log_runtime' do |app|
- setup_controller_runtime(app)
+ setup_controller_runtime app
end
initializer 'sequel.connect' do |app|
- Rails::Sequel.setup(Rails.env)
+ ::Rails::Sequel.setup ::Rails.env
end
# Run setup code after_initialize to make sure all config/initializers
@@ -69,13 +71,13 @@ class Railtie < Rails::Railtie
# Support overwriting crucial steps in subclasses
def configure_sequel(app)
- app.config.sequel = Rails::Sequel::Configuration.for(
- Rails.root, app.config.database_configuration
+ app.config.sequel = ::Rails::Sequel::Configuration.for(
+ ::Rails.root, app.config.database_configuration
)
end
def setup_i18n_support(app)
- ::Sequel::Model.send :include, Rails::Sequel::I18nSupport
+ ::Sequel::Model.send :include, ::Rails::Sequel::I18nSupport
end
def setup_controller_runtime(app)
@@ -84,7 +86,7 @@ def setup_controller_runtime(app)
end
def setup_logger(app, logger)
- app.config.sequel.logger=logger
+ app.config.sequel.logger = logger
end
end
@@ -1,4 +1,5 @@
-require 'active_support/core_ext/module/attr_internal'
+require "active_support/core_ext/module/attr_internal"
+require "sequel-rails/runtime"
module Rails
module Sequel
@@ -1,16 +1,13 @@
-require 'active_support/core_ext/hash/except'
-
-require 'sequel/extensions/migration'
-
-require 'sequel-rails/configuration'
-require 'sequel-rails/runtime'
-require 'sequel-rails/railties/benchmarking_mixin'
+require "sequel-rails/configuration"
module Rails
module Sequel
def self.setup(environment)
- ::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environment_for(environment.to_s)))
+ conf = configuration.environment_for(environment.to_s).reverse_merge({
+ logger: configuration.logger
+ })
+ ::Sequel.connect conf
end
end
@@ -0,0 +1,2 @@
+class User < Sequel::Model
+end
@@ -0,0 +1,7 @@
+test:
+ adapter: <%= ENV["TEST_ADAPTER"] || "postgresql" %>
+ database: <%= ENV["TEST_DATABASE"] || "sequel_rails_test" %>
+ owner: <%= ENV["TEST_OWNER"] || ENV["USER"] %>
+ username: <%= ENV["TEST_USERNAME"] || ENV["USER"] %>
+ password: <%= ENV["TEST_PASSWORD"] %>
+ encoding: <%= ENV["TEST_ENCODING"] || "unicode" %>
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do
+ #
+end
@@ -0,0 +1,8 @@
+Sequel.migration do
+ change do
+ create_table :users do
+ primary_key :id
+ String :email
+ end
+ end
+end
No changes.
@@ -0,0 +1,85 @@
+require "spec_helper"
+
+describe Rails::Sequel::Railtie do
+ it "registers ::Sequel::Railtie::LogSubscriber to receive :sequel notification" do
+ ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
+ subscriber.is_a?(Sequel::Railties::LogSubscriber)
+ end.should have(1).item
+ end
+
+ context "configures generator to use Sequel" do
+ it "as orm" do
+ Combustion::Application.config.generators.options[:rails][:orm].should == :sequel
+ end
+
+ it "for migrations" do
+ Combustion::Application.config.generators.options[:sequel][:migration].should be true
+ end
+ end
+
+ it "configures rails to use fancy pants logging" do
+ Combustion::Application.config.rails_fancy_pants_logging.should be true
+ end
+
+ context "configures action dispatch's rescue responses" do
+ let(:rescue_responses) do
+ Combustion::Application.config.action_dispatch.rescue_responses
+ end
+
+ it "to handle Sequel::Plugins::RailsExtensions::ModelNotFound with :not_found" do
+ rescue_responses["Sequel::Plugins::RailsExtensions::ModelNotFound"].should == :not_found
+ end
+
+ it "to handle Sequel::ValidationFailed with :unprocessable_entity" do
+ rescue_responses["Sequel::ValidationFailed"].should == :unprocessable_entity
+ end
+
+ it "to handle Sequel::NoExistingObject with :unprocessable_entity" do
+ rescue_responses["Sequel::NoExistingObject"].should == :unprocessable_entity
+ end
+ end
+
+ it "adds it's own database's rake tasks" do
+ pending "need to find a way to spec it"
+ end
+
+ it "stores it's own config in app.config.sequel" do
+ Combustion::Application.config.sequel.should be_instance_of Rails::Sequel::Configuration
+ end
+
+ it "sets Rails.logger as default logger for its configuration" do
+ Combustion::Application.config.sequel.logger.should be Rails.logger
+ end
+
+ it "configures Sequel::Model instances for i18n" do
+ User.new.i18n_scope.should == :sequel
+ end
+
+ it "adds Sequel runtime to controller for logging" do
+ ActionController::Base.included_modules.should include(
+ Rails::Sequel::Railties::ControllerRuntime
+ )
+ end
+
+ context "Sequel::Model is configured" do
+ let(:plugins) { Sequel::Model.plugins }
+ it "to use :active_model plugin" do
+ plugins.should include Sequel::Plugins::ActiveModel
+ end
+ it "to use :validation_helpers plugin" do
+ plugins.should include Sequel::Plugins::ValidationHelpers
+ end
+ it "to use :rails_extensions plugin" do
+ plugins.should include Sequel::Plugins::RailsExtensions
+ end
+ it "to not raise on save failure" do
+ Sequel::Model.raise_on_save_failure.should be false
+ end
+ end
+
+ it "configures database in Sequel" do
+ expect do
+ Sequel::Model.db.test_connection
+ end.to_not raise_error Sequel::Error
+ end
+end
View
@@ -1,4 +0,0 @@
---color
---loadby random
---format profile
---backtrace
Oops, something went wrong. Retry.

0 comments on commit 359b71a

Please sign in to comment.