<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

describe ImagesController do

  describe "Route generation" do
    it "should generate custom urls" do
      route_for({:controller => 'images', :action => 'custom', :geometry => '42x23', :filename => 'image_filename.jpg', :id => '5' }).should ==
        '/upload/images/5/custom/42x23/image_filename.jpg'
    end
  end

  describe "Route recognition" do
    it "should recognize custom urls without x" do
      params_from(:get, '/upload/images/5/custom/4223/image_filename.jpg').should == 
        {:controller => 'images', :action => 'custom', :geometry => '4223', :filename => 'image_filename.jpg', :id => "5"  }
    end
    it "should recognize custom urls" do
      params_from(:get, '/upload/images/5/custom/42x23/image_filename.jpg').should == 
        {:controller => 'images', :action => 'custom', :geometry => '42x23', :filename => 'image_filename.jpg', :id => "5"  }
    end
  end

  describe "using Toolbox" do
    before( :each ) do
      login_standard
      login_with_groups :admin_images
    end

    describe "uploading an image (multipart)" do
      def do_request
        filename = "%s/%s/%s" % [ File.dirname(__FILE__), '../../public/images', 'pentagon-tile.jpg' ]
        file = ActionController::TestUploadedFile.new(filename)
        Image.any_instance.stubs(:valid?).returns(true)
        Image.any_instance.stubs(:save).returns(true)
        Image.any_instance.stubs(:id).returns(2342)
        post :create, :image => {:image => file }, :format => 'js'
      end
      before( :each ) do
        do_request
      end

      it "should be successful" do
        response.should be_success
      end

      it "should wrap the JS response into HTML for iframe support" do
        response.body.should have_tag('html > body > script[type=text/javascript]', /window\.eval/)
      end
    end
    
  end

end
<commit_msg>spec ImageController with factories instead of any_instance sh*t<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe ImagesController do

  describe "Route generation" do
    it "should generate custom urls" do
      route_for({:controller => 'images', :action => 'custom', :geometry => '42x23', :filename => 'image_filename.jpg', :id => '5' }).should ==
        '/upload/images/5/custom/42x23/image_filename.jpg'
    end
  end

  describe "Route recognition" do
    it "should recognize custom urls without x" do
      params_from(:get, '/upload/images/5/custom/4223/image_filename.jpg').should == 
        {:controller => 'images', :action => 'custom', :geometry => '4223', :filename => 'image_filename.jpg', :id => "5"  }
    end
    it "should recognize custom urls" do
      params_from(:get, '/upload/images/5/custom/42x23/image_filename.jpg').should == 
        {:controller => 'images', :action => 'custom', :geometry => '42x23', :filename => 'image_filename.jpg', :id => "5"  }
    end
  end

  describe "using Toolbox" do
    before( :each ) do
      login_standard
      login_with_groups :admin_images
    end

    describe "uploading an image (multipart)" do
      def do_request
        filename = "%s/%s/%s" % [ File.dirname(__FILE__), '../../public/images', 'pentagon-tile.jpg' ]
        file = ActionController::TestUploadedFile.new(filename)
        image = Factory :image, :id => 2342
        Image.should_receive(:new).and_return(image)
        post :create, :image => {:image => file }, :format => 'js'
      end
      before( :each ) do
        do_request
      end

      it "should be successful" do
        response.should be_success
      end

      it "should wrap the JS response into HTML for iframe support" do
        response.body.should have_tag('html > body > script[type=text/javascript]', /window\.eval/)
      end
    end
    
  end

end

{'fraction_non_alphanumeric': 0.14206932773109243, 'fraction_numerical': 0.017857142857142856, 'mean_word_length': 2.934917355371901, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7047774', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1141, 'n_words': 302}