<commit_before>require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')

describe <%= class_name %>Controller do
  describe "handling GET /<%= table_name %>" do
  
    it "should be successful" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= class_name.singularize %>.stub!(:find).and_return([<%= file_name %>])
      get :index, :format => 'xml'
      response.should be_success
    end
  
    it "should find all <%= table_name %>" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= class_name.singularize %>.should_receive(:find).with(:all).and_return([<%= file_name %>])
      get :index, :format => 'xml'
    end
  
    it "should assign the found <%= table_name %> for the view" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= class_name.singularize %>.stub!(:find).and_return([<%= file_name %>])
      get :index, :format => 'xml'
      assigns[:<%= table_name %>].should == [<%= file_name %>]
    end
  end

  describe "handling GET /<%= table_name %>/1" do

    it "should be successful" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)
      get :show, :id => "1", :format => 'xml'
      response.should be_success
    end
  
    it "should find the <%= file_name %> requested" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= class_name.singularize %>.should_receive(:find).with("1").and_return(<%= file_name %>)
      get :show, :id => "1", :format => 'xml'
    end
  
    it "should assign the found <%= file_name %> for the view" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)
      get :show, :id => "1", :format => 'xml'
      assigns[:<%= file_name %>].should equal(<%= file_name %>)
    end
  end

  describe "handling POST /<%= table_name %>" do
    
    describe "with successful save" do
  
      it "should create a new <%= file_name %>" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.should_receive(:new).with({}).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:save).and_return(true)
        post :create, :<%= file_name %> => {}, :format => 'xml'
      end

      it "should be successful" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:new).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:save).and_return(true)
        post :create, :<%= file_name %> => {}, :format => 'xml'
        response.should be_success
      end
      
    end
    
    describe "with failed save" do
      
      it "should be unprocessable" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:new).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:save).and_return(false)
        post :create, :<%= file_name %> => {}, :format => 'xml'
        response.code.should == '422'
      end
      
      it "should return errors" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:new).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:save).and_return(false)
        post :create, :<%= file_name %> => {}, :format => 'xml'
        Nokogiri::XML(response.should).at('errors').should_not be_nil
      end
      
    end
  end

  describe "handling PUT /<%= table_name %>/1" do
    
    describe "with successful update" do

      it "should find the <%= file_name %> requested" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.should_receive(:find).with("1").and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
      end

      it "should update the found <%= file_name %>" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
        assigns(:<%= file_name %>).should equal(<%= file_name %>)
      end

      it "should assign the found <%= file_name %> for the view" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
        assigns(:<%= file_name %>).should equal(<%= file_name %>)
      end

      it "should be successful" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
        response.should be_success
      end

    end
    
    describe "with failed update" do

      it "should render errors" do
        <%= file_name %> = Factory(:<%= file_name %>)
        <%= file_name %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)
        <%= file_name %>.should_receive(:update_attributes).and_return(false)
        put :update, :id => "1", :format => 'xml'
        Nokogiri::XML(response.body).at('errors').should_not be_nil
      end

    end
  end

  describe "handling DELETE /<%= table_name %>/1" do

    it "should find the <%= file_name %> requested" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= file_name %>.stub!(:destroy).and_return(true)
      <%= class_name.singularize %>.should_receive(:find).with("1").and_return(<%= file_name %>)
      delete :destroy, :id => "1", :format => 'xml'
    end
  
    it "should call destroy on the found <%= file_name %>" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)
      <%= file_name %>.should_receive(:destroy).and_return(true) 
      delete :destroy, :id => "1", :format => 'xml'
    end
  
    it "should succeed" do
      <%= file_name %> = Factory(:<%= file_name %>)
      <%= file_name %>.stub!(:destroy).and_return(true)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name %>)<commit_msg>fix controller template<commit_after>require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')

describe <%= class_name %>Controller do
  describe "handling GET /<%= table_name %>" do
  
    it "should be successful" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= class_name.singularize %>.stub!(:find).and_return([<%= file_name.singularize %>])
      get :index, :format => 'xml'
      response.should be_success
    end
  
    it "should find all <%= table_name %>" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= class_name.singularize %>.should_receive(:find).with(:all).and_return([<%= file_name.singularize %>])
      get :index, :format => 'xml'
    end
  
    it "should assign the found <%= table_name %> for the view" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= class_name.singularize %>.stub!(:find).and_return([<%= file_name.singularize %>])
      get :index, :format => 'xml'
      assigns[:<%= file_name.singularize %>].should == [<%= file_name.singularize %>]
    end
  end

  describe "handling GET /<%= table_name %>/1" do

    it "should be successful" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
      get :show, :id => "1", :format => 'xml'
      response.should be_success
    end
  
    it "should find the <%= file_name.singularize %> requested" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= class_name.singularize %>.should_receive(:find).with("1").and_return(<%= file_name.singularize %>)
      get :show, :id => "1", :format => 'xml'
    end
  
    it "should assign the found <%= file_name.singularize %> for the view" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
      get :show, :id => "1", :format => 'xml'
      assigns[:<%= file_name.singularize %>].should equal(<%= file_name.singularize %>)
    end
  end

  describe "handling POST /<%= table_name %>" do
    
    describe "with successful save" do
  
      it "should create a new <%= file_name.singularize %>" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.should_receive(:new).with({}).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:save).and_return(true)
        post :create, :<%= file_name.singularize %> => {}, :format => 'xml'
      end

      it "should be successful" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:new).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:save).and_return(true)
        post :create, :<%= file_name %> => {}, :format => 'xml'
        response.should be_success
      end
      
    end
    
    describe "with failed save" do
      
      it "should be unprocessable" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:new).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:save).and_return(false)
        post :create, :<%= file_name.singularize %> => {}, :format => 'xml'
        response.code.should == '422'
      end
      
      it "should return errors" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:new).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:save).and_return(false)
        post :create, :<%= file_name.singularize %> => {}, :format => 'xml'
        Nokogiri::XML(response.body).at('errors').should_not be_nil
      end
      
    end
  end

  describe "handling PUT /<%= table_name %>/1" do
    
    describe "with successful update" do

      it "should find the <%= file_name.singularize %> requested" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.should_receive(:find).with("1").and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
      end

      it "should update the found <%= file_name.singularize %>" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
        assigns(:<%= file_name.singularize %>).should equal(<%= file_name.singularize %>)
      end

      it "should assign the found <%= file_name.singularize %> for the view" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
        assigns(:<%= file_name.singularize %>).should equal(<%= file_name.singularize %>)
      end

      it "should be successful" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:update_attributes).and_return(true)
        put :update, :id => "1", :format => 'xml'
        response.should be_success
      end

    end
    
    describe "with failed update" do

      it "should render errors" do
        <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
        <%= file_name.singularize %>.stub!(:to_param).and_return("1")
        <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
        <%= file_name.singularize %>.should_receive(:update_attributes).and_return(false)
        put :update, :id => "1", :format => 'xml'
        Nokogiri::XML(response.body).at('errors').should_not be_nil
      end

    end
  end

  describe "handling DELETE /<%= table_name %>/1" do

    it "should find the <%= file_name %> requested" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= file_name.singularize %>.stub!(:destroy).and_return(true)
      <%= class_name.singularize %>.should_receive(:find).with("1").and_return(<%= file_name.singularize %>)
      delete :destroy, :id => "1", :format => 'xml'
    end
  
    it "should call destroy on the found <%= file_name %>" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
      <%= file_name.singularize %>.should_receive(:destroy).and_return(true) 
      delete :destroy, :id => "1", :format => 'xml'
    end
  
    it "should succeed" do
      <%= file_name.singularize %> = Factory(:<%= file_name.singularize %>)
      <%= file_name.singularize %>.stub!(:destroy).and_return(true)
      <%= class_name.singularize %>.stub!(:find).and_return(<%= file_name.singularize %>)
{'fraction_non_alphanumeric': 0.19102095111406717, 'fraction_numerical': 0.0037246425008313935, 'mean_word_length': 3.1894678183337977, 'pattern_counts': {'":': 0, '<': 247, '<?xml version=': 0, '>': 309, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 34}, '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': '413862', 'n_tokens_mistral': 5421, 'n_tokens_neox': 4881, 'n_words': 952}