Note that there are some explanatory texts on larger screens.

plurals
  1. POKonacha adds 'iframe' to image urls that have the src attribute set programmatically
    primarykey
    data
    text
    <p>I have just managed to get Konacha running for my client side integration tests.</p> <p>Konacha runs the ember application in an iframe for testing. In my app, I create img elements programmatically based on user actions. When I set the 'src' attribute the resulting url that is used to fetch the image file from the server has the '/iframe' part added to it like so:</p> <pre><code>http://0.0.0.0:3500/iframe/assets/regensberg/regensberg_1.jpg </code></pre> <p>Which gives a <em>404 (Not Found)</em></p> <p>The code does run correctly when I serve it from a regular rails development server </p> <pre><code>rails s </code></pre> <p>The correct url should read:</p> <pre><code>http://0.0.0.0:3500/assets/regensberg/regensberg_1.jpg </code></pre> <p>Any ideas why it is doing this an how to get around it?</p> <p><strong>* Edit *</strong></p> <p>Looking into the Konacha code I find the routes defined in <em>konacha/config/routes.rb</em></p> <pre><code>Konacha::Engine.routes.draw do get '/iframe/*name' =&gt; 'specs#iframe', :format =&gt; false, :as =&gt; :iframe root :to =&gt; 'specs#parent' get '*path' =&gt; 'specs#parent', :format =&gt; false end </code></pre> <p>We see that this request gets passed to the iframe method in the specs controller.</p> <p><em>konacha/app/controllers/konacha/specs</em>_ <em>controller.rb</em> shows us where the 404 message comes from.</p> <pre><code>module Konacha class SpecsController &lt; ActionController::Base rescue_from Konacha::Spec::NotFound do render :text =&gt; "Not found", :status =&gt; 404 end def parent @run_mode = params.fetch(:mode, Konacha.mode).to_s.inquiry @specs = Konacha::Spec.all(params[:path]) end def iframe @spec = Konacha::Spec.find_by_name(params[:name]) @stylesheets = Konacha::Engine.config.konacha.stylesheets end end end </code></pre> <p>Looking into the model, we see where the <em>Spec::NotFound</em> comes from:</p> <pre><code>module Konacha class Spec class NotFound &lt; StandardError end def self.all(path = nil) paths = Konacha.spec_paths paths = ENV["SPEC"].split(",") if ENV["SPEC"] paths = paths.map { |p| new(p) } if path.present? paths = paths.select { |s| s.path.starts_with?(path) }.presence or raise NotFound end paths end def self.find_by_name(name) all.find { |s| s.asset_name == name } or raise NotFound end attr_accessor :path def initialize(path) @path = path end def asset_name path.sub(/(\.js|\.coffee).*/, '') end end end </code></pre> <p>With the above info, we see why we get the error message instead of the image file when we send the get request to the path that includes 'iframe'. So, why does the URL include 'iframe'?</p> <p>Looking into the parent view code:</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html;charset=utf-8" /&gt; &lt;title&gt;Konacha Tests&lt;/title&gt; &lt;%= stylesheet_link_tag "konacha", :debug =&gt; false %&gt; &lt;%= javascript_include_tag "mocha", "konacha/parent", :debug =&gt; false %&gt; &lt;%= javascript_include_tag("konacha/runner", :debug =&gt; false) if @run_mode.runner? %&gt; &lt;/head&gt; &lt;body&gt; &lt;% @specs.each do |spec| %&gt; &lt;%= content_tag :iframe, "", :src =&gt; iframe_path(spec.asset_name), :class =&gt; "test-context", "data-path" =&gt; spec.path %&gt; &lt;% end %&gt; &lt;div id="mocha"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>we see that the src for the iframe is the iframe path, which from the route above should be:</p> <pre><code> 0.0.0.0:3500/iframe/#{spec.assetName} </code></pre> <p>I set the img src paramter like this:</p> <pre><code>img.src = "assets/" + filename </code></pre> <p>the browser prepends "0.0.0.0:3500/iframe/" to this before making the request. This seems to be causing the real trouble. How to prevent the iframe from including this part in the base URL?</p> <p><strong>* Finish Edit *</strong></p> <p>By the way, can someone with a high-enough karma(>1500) create a Konacha tag?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload