diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb
index 4b642f50a79..5c3deb9b4e5 100644
--- a/app/models/site_customization.rb
+++ b/app/models/site_customization.rb
@@ -14,12 +14,26 @@ class SiteCustomization < ActiveRecord::Base
   end
 
   def compile_stylesheet(scss)
+    # Get the sprockets environment. In production Rails.application.assets is a
+    # Sprockets::Index instead of Sprockets::Environment, there is no cleaner way
+    # to get the environment from the index.
+    env = Rails.application.assets
+    if env.is_a?(Sprockets::Index)
+      env = env.instance_variable_get('@environment')
+    end
+
+    context = env.context_class.new(env, "custom.scss", "app/assets/stylesheets/custom.scss")
+
     ::Sass::Engine.new(scss, {
       syntax: :scss,
       cache: false,
       read_cache: false,
       style: :compressed,
-      filesystem_importer: DiscourseSassImporter
+      filesystem_importer: DiscourseSassImporter,
+      sprockets: {
+        context: context,
+        environment: env
+      }
     }).render
 
   rescue => e
diff --git a/spec/models/site_customization_spec.rb b/spec/models/site_customization_spec.rb
index 09f3d4e8152..3bfb89d3702 100644
--- a/spec/models/site_customization_spec.rb
+++ b/spec/models/site_customization_spec.rb
@@ -163,30 +163,12 @@ describe SiteCustomization do
       c.mobile_stylesheet_baked.should == "#a{color:#000}\n"
     end
 
-    pending 'should allow including discourse styles' do
+    it 'should allow including discourse styles' do
       c = SiteCustomization.create!(user_id: user.id, name: "test", stylesheet: '@import "desktop";', mobile_stylesheet: '@import "mobile";')
       c.stylesheet_baked.should_not =~ /Syntax error/
       c.stylesheet_baked.length.should > 1000
       c.mobile_stylesheet_baked.should_not =~ /Syntax error/
       c.mobile_stylesheet_baked.length.should > 1000
-
-      # Vikhyat, this is giving me an anurism
-      #
-      # SiteCustomisation is not initializing sprockets and sprockets enviroment, they are required for asset helpers to function properly
-      # in travis we see this failure quite often:
-      #
-      # /home/travis/.rvm/gems/ruby-2.1.1/gems/sprockets-2.11.0/lib/sprockets/sass_functions.rb:63:in `sprockets_context'
-      # /home/travis/.rvm/gems/ruby-2.1.1/gems/sass-rails-4.0.2/lib/sass/rails/helpers.rb:23:in `asset_url'
-      # /home/travis/.rvm/gems/ruby-2.1.1/gems/sass-3.2.16/lib/sass/script/funcall.rb:113:in `_perform'
-      # /home/travis/.rvm/gems/ruby-2.1.1/gems/sass-3.2.16/lib/sass/script/node.rb:40:in `perform'
-      # eg: https://travis-ci.org/discourse/discourse/jobs/22413830
-      #
-      # This makes sense cause our compile_stylesheet method does not specify sprockets: { context: ctx, environment: ctx.environment }
-      # Thing is, where do you even get this magic context object from and how do you generate it, perhaps Rails.application.assets.context_class.new ...
-      # I dunno, its all voodoo to me
-      #
-      # The "sometimes" failing thing also needs to be determined, this should either always fail or never fail, its a strong indicator that a bunch
-      # of caching is happening, please resolve and re-enable the test
     end
 
     it 'should provide an awesome error on failure' do