Skip to content

Commit

Permalink
fix code that figures out if the asset pipeline is enabled
Browse files Browse the repository at this point in the history
The Rails3-compatible algorithm to figure out if the asset pipeline is
doesn't work with Rails4.  Quite frankly, the new one doesn't seem as
clean as the old one, but hopefully this code will work in all cases.

rails/rails#10334

Note that the specs didn't seem to test both cases, or else the image
path is now the same whether the pipeline is enabled or not, but in
any case the specs don't need to determine whether the pipeline is
enabled, they can use the same path in all cases.
  • Loading branch information
toby cabot committed Aug 16, 2013
1 parent 940b299 commit 0f56592
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
9 changes: 7 additions & 2 deletions lib/surveyor/helpers/asset_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ module AssetPipeline
##
# Returns whether or not the asset pipeline is present and enabled.
#
# The detection scheme used here was ripped from jquery-rails.
# With Rails4 it appears that assets.enabled is false if
# --skip-sprockets is specified when creating the application,
# but the assets.enabled option is nil in the default case
# (i.e., pipeline enabled).
def asset_pipeline_enabled?
::Rails.version >= "3.1" && ::Rails.application.config.assets.enabled
return false unless Rails.configuration.respond_to?('assets')
assets = Rails.configuration.assets
assets.enabled.nil? || assets.enabled
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/helpers/surveyor_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

describe SurveyorHelper do
context "numbering" do
let(:asset_directory){ asset_pipeline_enabled? ? "assets" : "images" }
before do
ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
end
Expand All @@ -15,7 +14,7 @@
helper.q_text(q1).should == "<span class='qnum'>1) </span>#{q1.text}"
helper.q_text(q2).should == q2.text
helper.q_text(q3).should == q3.text
helper.q_text(q4).should == %Q(<img alt="Something" src="/#{asset_directory}/something.jpg" />)
helper.q_text(q4).should == %Q(<img alt="Something" src="/images/something.jpg" />)
helper.q_text(q5).should == q5.text
end
end
Expand Down Expand Up @@ -115,4 +114,4 @@ def rc_to_as(type_sym)
helper.rc_to_as(:date).should == :string # back to string
end
end
end
end
5 changes: 2 additions & 3 deletions spec/models/answer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,13 @@
end

context "for views" do
let(:asset_directory){ asset_pipeline_enabled? ? "assets" : "images" }
before do
ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
end
it "#text_for with #display_type == image" do
answer.text = "rails.png"
answer.display_type = :image
answer.text_for.should == %(<img alt="Rails" src="/#{asset_directory}/rails.png" />)
answer.text_for.should == %(<img alt="Rails" src="/images/rails.png" />)
end
it "#text_for with #display_type == hidden_label" do
answer.text = "Red"
Expand Down Expand Up @@ -172,4 +171,4 @@
answer.text_for(:post).should == "after|extra"
end
end
end
end
3 changes: 1 addition & 2 deletions spec/models/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,13 @@
end

context "for views" do
let(:asset_directory){ asset_pipeline_enabled? ? "assets" : "images" }
before do
ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
end
it "#text_for with #display_type == image" do
question.text = "rails.png"
question.display_type = :image
question.text_for.should == %(<img alt="Rails" src="/#{asset_directory}/rails.png" />)
question.text_for.should == %(<img alt="Rails" src="/images/rails.png" />)
end
it "#help_text_for"
it "#text_for preserves strings" do
Expand Down

0 comments on commit 0f56592

Please sign in to comment.