<commit_before>####################################################################
#                                                                  #
#      Copyright (c) 2008, <NAME> and others                  #
#      All Rights Reserved.                                        #
#                                                                  #
#      Licensed under the MIT License.                             #
#      For more information on d-rails licensing, see:             #
#                                                                  #
#          http://www.opensource.org/licenses/mit-license.php      #
#                                                                  #
####################################################################

require File.join(File.dirname(__FILE__), "../spec_helper.rb")

describe Drails::ScriptaculousHelper do
  attr_reader :test_view
  before do
    @test_view = TestView.new
    Drails::ScriptaculousOverride.override
  end

  describe "#visual_effect" do
    attr_reader :helper_output
    
    describe "when name is passed" do
      before do
        @helper_output = test_view.visual_effect("foo")
      end
      
      it "generates a JS effect constructor for the name" do
        helper_output.should == 'new drails.Effect.Foo(element,{});'
      end
      
      describe "when name is a TOGGLE_EFFECT" do
        before do
          @helper_output = test_view.visual_effect(:toggle_appear, "my_id")
        end
        it "calles .toggle on drails.Effect with ID as the first param, the effect as the second param, and options as the third param" do
          helper_output.should == "drails.Effect.toggle(\"my_id\",'appear',{});"
        end
      end
      
      describe "when element is passed" do
        before do
          @helper_output = test_view.visual_effect("foo", "my_id")
        end

        it "generates a JS effect constructor for the element" do
          helper_output.should == 'new drails.Effect.Foo("my_id",{});'
        end
      end
      
      describe "when js_options are passed" do
        before do
          options = {
            :endcolor => "#0000ff",
            :direction => "up",
            :startcolor => "#ff0000",
            :scaleMode => "scale",
            :restorecolor => true,
            :queue => { :limit => 100, :bar => "baz" }
          }
          @helper_output = test_view.visual_effect("foo", "my_id", options)
        end
        
        it "passes the hash as the effect options" do
          helper_output.should == "new drails.Effect.Foo(\"my_id\",{direction:'up', endcolor:'#0000ff', queue:{limit:100,bar:'baz'}, restorecolor:'true', scaleMode:'scale', startcolor:'#ff0000'});"
        end
      end
      
    end
  end
  
  describe "#sortable_element_js" do
    attr_reader :helper_output

    before do
      @helper_output = test_view.sortable_element_js('my_id')
    end
    
    it "pending specs" do
      helper_output.should == 'drails.Sortable.create("my_id", {onUpdate:function(){new drails.Request(\'http://somemockurl.com\', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("my_id")})}});'
    end
  end
  
  describe "#draggable_element_js" do
    attr_reader :helper_output

    before do
      @helper_output = test_view.draggable_element_js('my_id')
      helper_output.should_not be_blank
    end
    
    it "pending specs" do
      pending
    end
  end
  
  describe "#drop_receiving_element_js" do
    attr_reader :helper_output

    before do
      @helper_output = test_view.drop_receiving_element_js('my_id')
      helper_output.should_not be_blank
    end<commit_msg>Added specs for #sortable_element_js<commit_after>####################################################################
#                                                                  #
#      Copyright (c) 2008, <NAME> and others                  #
#      All Rights Reserved.                                        #
#                                                                  #
#      Licensed under the MIT License.                             #
#      For more information on d-rails licensing, see:             #
#                                                                  #
#          http://www.opensource.org/licenses/mit-license.php      #
#                                                                  #
####################################################################

require File.join(File.dirname(__FILE__), "../spec_helper.rb")

describe Drails::ScriptaculousHelper do
  attr_reader :test_view
  before do
    @test_view = TestView.new
    Drails::ScriptaculousOverride.override
  end

  describe "#visual_effect" do
    attr_reader :helper_output
    
    describe "when name is passed" do
      before do
        @helper_output = test_view.visual_effect("foo")
      end
      
      it "generates a JS effect constructor for the name" do
        helper_output.should == 'new drails.Effect.Foo(element,{});'
      end
      
      describe "when name is a TOGGLE_EFFECT" do
        before do
          @helper_output = test_view.visual_effect(:toggle_appear, "my_id")
        end
        it "calles .toggle on drails.Effect with ID as the first param, the effect as the second param, and options as the third param" do
          helper_output.should == "drails.Effect.toggle(\"my_id\",'appear',{});"
        end
      end
      
      describe "when element is passed" do
        before do
          @helper_output = test_view.visual_effect("foo", "my_id")
        end

        it "generates a JS effect constructor for the element" do
          helper_output.should == 'new drails.Effect.Foo("my_id",{});'
        end
      end
      
      describe "when js_options are passed" do
        before do
          options = {
            :endcolor => "#0000ff",
            :direction => "up",
            :startcolor => "#ff0000",
            :scaleMode => "scale",
            :restorecolor => true,
            :queue => { :limit => 100, :bar => "baz" }
          }
          @helper_output = test_view.visual_effect("foo", "my_id", options)
        end
        
        it "passes the hash as the effect options" do
          helper_output.should == "new drails.Effect.Foo(\"my_id\",{direction:'up', endcolor:'#0000ff', queue:{limit:100,bar:'baz'}, restorecolor:'true', scaleMode:'scale', startcolor:'#ff0000'});"
        end
      end
      
    end
  end
  
  describe "#sortable_element_js" do
    attr_reader :helper_output

    before do
      @helper_output = test_view.sortable_element_js('my_id')
    end
    
    describe "when the element is passed" do
      it "returns the drails.Sortable.create method with the default onUpdate  callback" do
        helper_output.should == 'drails.Sortable.create("my_id", {onUpdate:function(){new drails.Request(\'http://somemockurl.com\', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("my_id")})}});'
      end
    end
    
    describe "when :with is passed" do
      before do
        @helper_output = test_view.sortable_element_js('my_id', :with => "function(){}")
      end
      
      it "returns extra parameters" do
        helper_output.should == "drails.Sortable.create(\"my_id\", {onUpdate:function(){new drails.Request('http://somemockurl.com', {asynchronous:true, evalScripts:true, parameters:function(){}})}});"
      end
    end
    
    describe "when :onUpdate is passed" do
      before do
        @helper_output = test_view.sortable_element_js('my_id', :onUpdate => "function(){}")
      end
      
      it "returns a custom callback instead of a drails.Request" do
        helper_output.should == "drails.Sortable.create(\"my_id\", {onUpdate:function(){}});"
      end
    end
    
    describe "when sortable specific params are passed" do
      before do
        options = {
          :tag => "tag",
          :overlap => true,
          :constraint => "if (true)",
          :handle => "handleIt()",
          :containment => [ 'blah', 'blah2' ],
          :only => ['boo', 'boo2']
        }
        @helper_output = test_view.sortable_element_js('my_id', options)
      end
      it "returns a drails.Sortable with all of the options" do
        helper_output.should == "drails.Sortable.create(\"my_id\", {constraint:'if (true)', containment:['blah','blah2'], handle:'handleIt()', onUpdate:function(){new drails.Request('http://somemockurl.com', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"my_id\")})}, only:['boo','boo2'], overlap:'true', tag:'tag'});"
      end
    end
  end
  
  describe "#draggable_element_js" do
    attr_reader :helper_output

    before do
      @helper_output = test_view.draggable_element_js('my_id')
      helper_output.should_not be_blank
    end
    
    it "pending specs" do
      pending
    end
  end
  
  describe "#drop_receiving_element_js" do
    attr_reader :helper_output

    before do
      @helper_output = test_view.drop_receiving_element_js('my_id')
      helper_output.should_not be_blank
    end
{'fraction_non_alphanumeric': 0.13570167696381288, 'fraction_numerical': 0.00617828773168579, 'mean_word_length': 2.0521885521885523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3300942', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2484, 'n_words': 606}