Permalink
Browse files

Add railtie and in_bed_with helper

  • Loading branch information...
1 parent e552174 commit 8b8c4bc1732f68ccd0c580abb8a4a4cc4a863b06 Sebastian von Conrad committed Jan 8, 2012
Showing with 42 additions and 0 deletions.
  1. +2 −0 lib/in_bed_with.rb
  2. +19 −0 lib/in_bed_with/railtie.rb
  3. +19 −0 spec/in_bed_with/rails_spec.rb
  4. +2 −0 spec/spec_helper.rb
View
@@ -6,6 +6,8 @@
require 'in_bed_with/analytics'
+require 'in_bed_with/railtie' if defined?(Rails)
+
module InBedWith
mattr_accessor :analytics_property_id
View
@@ -0,0 +1,19 @@
+require 'rails/railtie'
+
+module InBedWith
+ module Rails
+ module Helper
+ def in_bed_with
+ InBedWith
+ end
+ end
+
+ class Railtie < ::Rails::Railtie
+ initializer 'in_bed_with' do |app|
+ ActiveSupport.on_load(:action_view) do
+ extend Helper
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+module TestApp
+ class Application < Rails::Application
+ config.active_support.deprecation = :log
+ end
+end
+TestApp::Application.initialize!
+
+describe ActionView::Base do
+ it 'should add in_bed_with helper through railtie' do
+ InBedWith.config { |config| config.analytics_property_id = 'UA-7654321-1' }
+
+ ActionView::Base.should respond_to(:in_bed_with)
+
+ ActionView::Base.in_bed_with.should == InBedWith
+ ActionView::Base.in_bed_with.analytics.should =~ /UA-7654321-1/
+ end
+end
View
@@ -1,3 +1,5 @@
+require 'bundler/setup'
+require 'rails/all'
require File.join(File.dirname(__FILE__), '..', 'lib', 'in_bed_with')
RSpec.configure do |config|

0 comments on commit 8b8c4bc

Please sign in to comment.