Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add first round of specs

  • Loading branch information...
commit 359b71adc3f4e5e3f6cedf6683ea86778f92c42a 1 parent a33093c
Jonathan Tron authored
3  .rspec
... ...
@@ -0,0 +1,3 @@
  1
+--color
  2
+--format progress
  3
+--backtrace
4  Gemfile
... ...
@@ -1,3 +1,5 @@
1 1
 source "http://rubygems.org"
2 2
 
3  
-gemspec
  3
+gemspec
  4
+
  5
+gem "rspec-rails", require: false
55  Gemfile.lock
@@ -8,7 +8,9 @@ PATH
8 8
 GEM
9 9
   remote: http://rubygems.org/
10 10
   specs:
11  
-    ZenTest (4.6.2)
  11
+    actionmailer (3.2.9)
  12
+      actionpack (= 3.2.9)
  13
+      mail (~> 2.4.4)
12 14
     actionpack (3.2.9)
13 15
       activemodel (= 3.2.9)
14 16
       activesupport (= 3.2.9)
@@ -22,19 +24,36 @@ GEM
22 24
     activemodel (3.2.9)
23 25
       activesupport (= 3.2.9)
24 26
       builder (~> 3.0.0)
  27
+    activerecord (3.2.9)
  28
+      activemodel (= 3.2.9)
  29
+      activesupport (= 3.2.9)
  30
+      arel (~> 3.0.2)
  31
+      tzinfo (~> 0.3.29)
  32
+    activeresource (3.2.9)
  33
+      activemodel (= 3.2.9)
  34
+      activesupport (= 3.2.9)
25 35
     activesupport (3.2.9)
26 36
       i18n (~> 0.6)
27 37
       multi_json (~> 1.0)
28  
-    autotest (4.4.6)
29  
-      ZenTest (>= 4.4.1)
  38
+    arel (3.0.2)
30 39
     builder (3.0.4)
  40
+    combustion (0.3.3)
  41
+      rails (>= 3.0.0)
  42
+      thor (>= 0.14.6)
31 43
     diff-lcs (1.1.3)
32 44
     erubis (2.7.0)
33 45
     hike (1.2.1)
34 46
     i18n (0.6.1)
35 47
     journey (1.0.4)
36 48
     json (1.7.5)
  49
+    mail (2.4.4)
  50
+      i18n (>= 0.4.0)
  51
+      mime-types (~> 1.16)
  52
+      treetop (~> 1.4.8)
  53
+    mime-types (1.19)
37 54
     multi_json (1.4.0)
  55
+    pg (0.14.1)
  56
+    polyglot (0.3.3)
38 57
     rack (1.4.1)
39 58
     rack-cache (1.2)
40 59
       rack (>= 0.4)
@@ -42,6 +61,14 @@ GEM
42 61
       rack
43 62
     rack-test (0.6.2)
44 63
       rack (>= 1.0)
  64
+    rails (3.2.9)
  65
+      actionmailer (= 3.2.9)
  66
+      actionpack (= 3.2.9)
  67
+      activerecord (= 3.2.9)
  68
+      activeresource (= 3.2.9)
  69
+      activesupport (= 3.2.9)
  70
+      bundler (~> 1.0)
  71
+      railties (= 3.2.9)
45 72
     railties (3.2.9)
46 73
       actionpack (= 3.2.9)
47 74
       activesupport (= 3.2.9)
@@ -49,8 +76,7 @@ GEM
49 76
       rake (>= 0.8.7)
50 77
       rdoc (~> 3.4)
51 78
       thor (>= 0.14.6, < 2.0)
52  
-    rake (0.8.7)
53  
-    rcov (0.9.11)
  79
+    rake (10.0.3)
54 80
     rdoc (3.12)
55 81
       json (~> 1.4)
56 82
     rspec (2.7.0)
@@ -61,6 +87,11 @@ GEM
61 87
     rspec-expectations (2.7.0)
62 88
       diff-lcs (~> 1.1.2)
63 89
     rspec-mocks (2.7.0)
  90
+    rspec-rails (2.7.0)
  91
+      actionpack (~> 3.0)
  92
+      activesupport (~> 3.0)
  93
+      railties (~> 3.0)
  94
+      rspec (~> 2.7.0)
64 95
     sequel (3.42.0)
65 96
     sprockets (2.2.2)
66 97
       hike (~> 1.2)
@@ -69,15 +100,17 @@ GEM
69 100
       tilt (~> 1.1, != 1.3.0)
70 101
     thor (0.16.0)
71 102
     tilt (1.3.3)
72  
-    yard (0.7.3)
  103
+    treetop (1.4.12)
  104
+      polyglot
  105
+      polyglot (>= 0.3.1)
  106
+    tzinfo (0.3.35)
73 107
 
74 108
 PLATFORMS
75 109
   ruby
76 110
 
77 111
 DEPENDENCIES
78  
-  autotest (~> 4.4.6)
79  
-  rake (~> 0.8.7)
80  
-  rcov (~> 0.9.11)
81  
-  rspec (~> 2.7.0)
  112
+  combustion (~> 0.3.1)
  113
+  pg
  114
+  rake (>= 0.8.7)
  115
+  rspec-rails
82 116
   talentbox-sequel-rails!
83  
-  yard (~> 0.5)
7  config.ru
... ...
@@ -0,0 +1,7 @@
  1
+require 'rubygems'
  2
+require 'bundler'
  3
+
  4
+Bundler.require :default, :development
  5
+
  6
+Combustion.initialize!
  7
+run Combustion::Application
3  lib/sequel-rails.rb
... ...
@@ -1,7 +1,6 @@
1  
-require 'sequel-rails/railtie'
2  
-
3 1
 module Rails
4 2
   module Sequel
5 3
   end
6 4
 end
7 5
 
  6
+require 'sequel-rails/railtie'
3  lib/sequel-rails/configuration.rb
... ...
@@ -1,4 +1,3 @@
1  
-require 'active_support/core_ext/hash/except'
2 1
 require 'active_support/core_ext/class/attribute_accessors'
3 2
 
4 3
 module Rails
@@ -9,7 +8,7 @@ module Sequel
9 8
     class Configuration
10 9
 
11 10
       def self.for(root, database_yml_hash)
12  
-        Rails::Sequel.configuration ||= new(root, database_yml_hash)
  11
+        ::Rails::Sequel.configuration ||= new(root, database_yml_hash)
13 12
       end
14 13
 
15 14
       attr_reader :root, :raw
38  lib/sequel-rails/railtie.rb
... ...
@@ -1,20 +1,22 @@
1  
-require 'sequel'
  1
+require "sequel"
2 2
 
3  
-require 'rails'
4  
-require 'active_model/railtie'
  3
+require "rails"
  4
+require "active_model/railtie"
5 5
 
6 6
 # Comment taken from active_record/railtie.rb
7 7
 #
8 8
 # For now, action_controller must always be present with
9  
-# rails, so let's make sure that it gets required before
  9
+# rails, so let"s make sure that it gets required before
10 10
 # here. This is needed for correctly setting up the middleware.
11 11
 # In the future, this might become an optional require.
12  
-require 'action_controller/railtie'
13  
-
14  
-require 'sequel-rails/setup'
15  
-require 'sequel-rails/railties/log_subscriber'
16  
-require 'sequel-rails/railties/i18n_support'
  12
+require "action_controller/railtie"
17 13
 
  14
+require "sequel-rails/setup"
  15
+require "sequel-rails/migrations"
  16
+require "sequel-rails/railties/log_subscriber"
  17
+require "sequel-rails/railties/i18n_support"
  18
+require "sequel-rails/railties/controller_runtime"
  19
+require "sequel/plugins/rails_extensions"
18 20
 
19 21
 module Rails
20 22
   module Sequel
@@ -37,24 +39,24 @@ class Railtie < Rails::Railtie
37 39
       end
38 40
 
39 41
       initializer 'sequel.configuration' do |app|
40  
-        configure_sequel(app)
  42
+        configure_sequel app
41 43
       end
42 44
 
43 45
       initializer 'sequel.logger' do |app|
44  
-        setup_logger(app, Rails.logger)
  46
+        setup_logger app, ::Rails.logger
45 47
       end
46 48
 
47 49
       initializer 'sequel.i18n_support' do |app|
48  
-        setup_i18n_support(app)
  50
+        setup_i18n_support app
49 51
       end
50 52
 
51 53
       # Expose database runtime to controller for logging.
52 54
       initializer 'sequel.log_runtime' do |app|
53  
-        setup_controller_runtime(app)
  55
+        setup_controller_runtime app
54 56
       end
55 57
 
56 58
       initializer 'sequel.connect' do |app|
57  
-        Rails::Sequel.setup(Rails.env)
  59
+        ::Rails::Sequel.setup ::Rails.env
58 60
       end
59 61
 
60 62
       # Run setup code after_initialize to make sure all config/initializers
@@ -69,13 +71,13 @@ class Railtie < Rails::Railtie
69 71
 
70 72
       # Support overwriting crucial steps in subclasses
71 73
       def configure_sequel(app)
72  
-        app.config.sequel = Rails::Sequel::Configuration.for(
73  
-          Rails.root, app.config.database_configuration
  74
+        app.config.sequel = ::Rails::Sequel::Configuration.for(
  75
+          ::Rails.root, app.config.database_configuration
74 76
         )
75 77
       end
76 78
 
77 79
       def setup_i18n_support(app)
78  
-        ::Sequel::Model.send :include, Rails::Sequel::I18nSupport
  80
+        ::Sequel::Model.send :include, ::Rails::Sequel::I18nSupport
79 81
       end
80 82
 
81 83
       def setup_controller_runtime(app)
@@ -84,7 +86,7 @@ def setup_controller_runtime(app)
84 86
       end
85 87
 
86 88
       def setup_logger(app, logger)
87  
-        app.config.sequel.logger=logger
  89
+        app.config.sequel.logger = logger
88 90
       end
89 91
 
90 92
     end
3  lib/sequel-rails/railties/controller_runtime.rb
... ...
@@ -1,4 +1,5 @@
1  
-require 'active_support/core_ext/module/attr_internal'
  1
+require "active_support/core_ext/module/attr_internal"
  2
+require "sequel-rails/runtime"
2 3
 
3 4
 module Rails
4 5
   module Sequel
13  lib/sequel-rails/setup.rb
... ...
@@ -1,16 +1,13 @@
1  
-require 'active_support/core_ext/hash/except'
2  
-
3  
-require 'sequel/extensions/migration'
4  
-
5  
-require 'sequel-rails/configuration'
6  
-require 'sequel-rails/runtime'
7  
-require 'sequel-rails/railties/benchmarking_mixin'
  1
+require "sequel-rails/configuration"
8 2
 
9 3
 module Rails
10 4
   module Sequel
11 5
 
12 6
     def self.setup(environment)
13  
-      ::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environment_for(environment.to_s)))
  7
+      conf = configuration.environment_for(environment.to_s).reverse_merge({
  8
+        logger: configuration.logger
  9
+      })
  10
+      ::Sequel.connect conf
14 11
     end
15 12
 
16 13
   end
2  spec/internal/app/models/user.rb
... ...
@@ -0,0 +1,2 @@
  1
+class User < Sequel::Model
  2
+end
7  spec/internal/config/database.yml
... ...
@@ -0,0 +1,7 @@
  1
+test:
  2
+  adapter: <%= ENV["TEST_ADAPTER"] || "postgresql" %>
  3
+  database: <%= ENV["TEST_DATABASE"] || "sequel_rails_test" %>
  4
+  owner: <%= ENV["TEST_OWNER"] || ENV["USER"] %>
  5
+  username: <%= ENV["TEST_USERNAME"] || ENV["USER"] %>
  6
+  password: <%= ENV["TEST_PASSWORD"] %>
  7
+  encoding: <%= ENV["TEST_ENCODING"] || "unicode" %>
3  spec/internal/config/routes.rb
... ...
@@ -0,0 +1,3 @@
  1
+Rails.application.routes.draw do
  2
+  #
  3
+end
8  spec/internal/db/schema.rb
... ...
@@ -0,0 +1,8 @@
  1
+Sequel.migration do
  2
+  change do
  3
+    create_table :users do
  4
+      primary_key :id
  5
+      String      :email
  6
+    end
  7
+  end
  8
+end
0  spec/internal/public/favicon.ico
No changes.
85  spec/lib/sequel-rails/railtie_spec.rb
... ...
@@ -0,0 +1,85 @@
  1
+require "spec_helper"
  2
+
  3
+describe Rails::Sequel::Railtie do
  4
+  it "registers ::Sequel::Railtie::LogSubscriber to receive :sequel notification" do
  5
+    ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
  6
+      subscriber.is_a?(Sequel::Railties::LogSubscriber)
  7
+    end.should have(1).item
  8
+  end
  9
+
  10
+  context "configures generator to use Sequel" do
  11
+    it "as orm" do
  12
+      Combustion::Application.config.generators.options[:rails][:orm].should == :sequel
  13
+    end
  14
+
  15
+    it "for migrations" do
  16
+      Combustion::Application.config.generators.options[:sequel][:migration].should be true
  17
+    end
  18
+  end
  19
+
  20
+  it "configures rails to use fancy pants logging" do
  21
+    Combustion::Application.config.rails_fancy_pants_logging.should be true
  22
+  end
  23
+
  24
+  context "configures action dispatch's rescue responses" do
  25
+    let(:rescue_responses) do
  26
+      Combustion::Application.config.action_dispatch.rescue_responses
  27
+    end
  28
+
  29
+    it "to handle Sequel::Plugins::RailsExtensions::ModelNotFound with :not_found" do
  30
+      rescue_responses["Sequel::Plugins::RailsExtensions::ModelNotFound"].should == :not_found
  31
+    end
  32
+
  33
+    it "to handle Sequel::ValidationFailed with :unprocessable_entity" do
  34
+      rescue_responses["Sequel::ValidationFailed"].should == :unprocessable_entity
  35
+    end
  36
+
  37
+    it "to handle Sequel::NoExistingObject with :unprocessable_entity" do
  38
+      rescue_responses["Sequel::NoExistingObject"].should == :unprocessable_entity
  39
+    end
  40
+  end
  41
+
  42
+  it "adds it's own database's rake tasks" do
  43
+    pending "need to find a way to spec it"
  44
+  end
  45
+
  46
+  it "stores it's own config in app.config.sequel" do
  47
+    Combustion::Application.config.sequel.should be_instance_of Rails::Sequel::Configuration
  48
+  end
  49
+
  50
+  it "sets Rails.logger as default logger for its configuration" do
  51
+    Combustion::Application.config.sequel.logger.should be Rails.logger
  52
+  end
  53
+
  54
+  it "configures Sequel::Model instances for i18n" do
  55
+    User.new.i18n_scope.should == :sequel
  56
+  end
  57
+
  58
+  it "adds Sequel runtime to controller for logging" do
  59
+    ActionController::Base.included_modules.should include(
  60
+      Rails::Sequel::Railties::ControllerRuntime
  61
+    )
  62
+  end
  63
+
  64
+  context "Sequel::Model is configured" do
  65
+    let(:plugins) { Sequel::Model.plugins }
  66
+    it "to use :active_model plugin" do
  67
+      plugins.should include Sequel::Plugins::ActiveModel
  68
+    end
  69
+    it "to use :validation_helpers plugin" do
  70
+      plugins.should include Sequel::Plugins::ValidationHelpers
  71
+    end
  72
+    it "to use :rails_extensions plugin" do
  73
+      plugins.should include Sequel::Plugins::RailsExtensions
  74
+    end
  75
+    it "to not raise on save failure" do
  76
+      Sequel::Model.raise_on_save_failure.should be false
  77
+    end
  78
+  end
  79
+
  80
+  it "configures database in Sequel" do
  81
+    expect do
  82
+      Sequel::Model.db.test_connection
  83
+    end.to_not raise_error Sequel::Error
  84
+  end
  85
+end
4  spec/spec.opts
... ...
@@ -1,4 +0,0 @@
1  
---color
2  
---loadby random
3  
---format profile
4  
---backtrace
26  spec/spec_helper.rb
... ...
@@ -1,7 +1,31 @@
1  
-require "sequel-rails"
  1
+require "rubygems"
  2
+require "bundler"
  3
+
  4
+Bundler.require :default, :development, :test
  5
+
  6
+# Combustion initialization has to happend before loading rspec/rails
  7
+Combustion.initialize! "sequel-rails"
  8
+
  9
+require "rspec/rails"
2 10
 
3 11
 # Load support files
4 12
 Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
5 13
 
6 14
 RSpec.configure do |config|
  15
+  config.around :each do |example|
  16
+    Sequel::Model.db.transaction(rollback: :always) do
  17
+      example.run
  18
+    end
  19
+  end
  20
+end
  21
+
  22
+# Ensure db exists and clean state
  23
+begin
  24
+  db = Sequel::Model.db
  25
+  all_tables = (db.tables-[:schema_info, :schema_migrations]).map{|t| %["#{t}"]}.join ','
  26
+  db.run "TRUNCATE TABLE #{all_tables} RESTART IDENTITY" unless all_tables.empty?
  27
+rescue Sequel::DatabaseConnectionError => e
  28
+  puts "Database connection error: #{e.message}"
  29
+  puts "Ensure test db exists before running specs."
  30
+  exit 1
7 31
 end
9  talentbox-sequel-rails.gemspec
@@ -21,9 +21,8 @@ Gem::Specification.new do |s|
21 21
   s.add_runtime_dependency("sequel", ["~> 3.28"])
22 22
   s.add_runtime_dependency("railties", ["~> 3.2.0"])
23 23
 
24  
-  s.add_development_dependency("rake", ["~> 0.8.7"])
25  
-  s.add_development_dependency("yard", ["~> 0.5"])
26  
-  s.add_development_dependency("rspec", ["~> 2.7.0"])
27  
-  s.add_development_dependency("autotest", ["~> 4.4.6"])
28  
-  s.add_development_dependency("rcov", ["~> 0.9.11"])
  24
+  s.add_development_dependency "rake", ">= 0.8.7"
  25
+  s.add_development_dependency "rspec-rails", "~> 2.7.0"
  26
+  s.add_development_dependency "combustion", "~> 0.3.1"
  27
+  s.add_development_dependency "pg"
29 28
 end
17  tasks/spec.rake
@@ -11,20 +11,3 @@ rescue LoadError
11 11
   end
12 12
 end
13 13
 
14  
-begin
15  
-  namespace :spec do
16  
-    desc "Run all specs in spec directory with RCov (excluding plugin specs)"
17  
-    RSpec::Core::RakeTask.new(:rcov) do |t|
18  
-      t.rcov = true
19  
-      t.rcov_opts = lambda do
20  
-        IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
21  
-      end
22  
-    end
23  
-  end
24  
-rescue LoadError
25  
-  namespace :spec do
26  
-    task :rcov do
27  
-      abort "rcov is not available. In order to run #{name}, you must: bundle install"
28  
-    end
29  
-  end
30  
-end

0 notes on commit 359b71a

Please sign in to comment.
Something went wrong with that request. Please try again.