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

describe ReportsController do
  it_should_behave_like "an authenticated controller"
  it_should_behave_like "an authorized controller"

  describe 'team_notes' do

    describe 'GET' do
      it 'should set instance variables' do
        get :team_notes

        [:today, :start_date, :end_date].each do |sym|
          assigns[sym].should == Date.current
        end

        assigns[:filetypes].should == ['html', 'pdf', 'csv']
        assigns[:selected_filetype].should == 'html'
        assigns[:report].should be_nil
      end
    end

    describe 'POST' do
      describe 'with HTML format choice'
      it 'should return output of TeamNotesReport.render_html as report' do
        m = 'This is the HTML Team Notes Report Content'
        TeamNotesReport.stub!(:render_html).return(m)

        post :team_notes, :start_date => {:month => 10, :day => 15, :year => 2008}, :end_date => {:month => 10, :day => 19, :year => 2008},
          "report_params"=>{"format"=>"html"}, "generate"=>"Generate Report"

        assigns[:today].should == Date.current
        assigns[:start_date].should == Date.new(2008, 10, 15)
        assigns[:end_date].should == Date.new(2008, 10, 19)

        assigns[:filetypes].should == ['html', 'pdf', 'csv']
        assigns[:selected_filetype].should == 'html'

        assigns[:report].class.should == String
        assigns[:report].should == m
      end

      describe 'and CSV format choice' do
        it 'returns output of TeamNotesReport.render_csv as report' do
          m = 'This is the CSV Team Notes Report Content'
          TeamNotesReport.stub!(:render_csv).return(m)

          post :team_notes, {:generate => "Do the report", :report_params => {:format => 'csv'}}, {:user_id => 1}
          assigns[:report].should equal(m)
          assert_template nil # not sure how to do this with an Rspec matcher...

          response.should be_success
          response.body.should equal(m)
        end
      end # CSV

      describe 'and PDF format choice' do
        it 'returns output of TeamNotesReport.render_pdf as report' do
          m = 'This is the PDF Team Notes Report Content'
          TeamNotesReport.stub!(:render_pdf).return(m)

          post :team_notes, {:generate => "Do the report", :report_params => {:format => 'pdf'}}, {:user_id => 1}
          assigns[:report].should equal(m)
          assert_template nil # not sure how to do this with an Rspec matcher...

          response.should be_success
          response.body.should equal(m)
        end
      end # PDF
      
    end
  end
end<commit_msg>I think we were confusing mocha and rspect stubs<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe ReportsController do
  it_should_behave_like "an authenticated controller"
  it_should_behave_like "an authorized controller"

  describe 'team_notes' do

    describe 'GET' do
      it 'should set instance variables' do
        get :team_notes

        [:today, :start_date, :end_date].each do |sym|
          assigns[sym].should == Date.current
        end

        assigns[:filetypes].should == ['html', 'pdf', 'csv']
        assigns[:selected_filetype].should == 'html'
        assigns[:report].should be_nil
      end
    end

    describe 'POST' do
      describe 'with HTML format choice'
      it 'should return output of TeamNotesReport.render_html as report' do
        m = 'This is the HTML Team Notes Report Content'
        TeamNotesReport.stub!(:render_html=>m)

        post :team_notes, :start_date => {:month => 10, :day => 15, :year => 2008}, :end_date => {:month => 10, :day => 19, :year => 2008},
          "report_params"=>{"format"=>"html"}, "generate"=>"Generate Report"

        assigns[:today].should == Date.current
        assigns[:start_date].should == Date.new(2008, 10, 15)
        assigns[:end_date].should == Date.new(2008, 10, 19)

        assigns[:filetypes].should == ['html', 'pdf', 'csv']
        assigns[:selected_filetype].should == 'html'

        assigns[:report].class.should == String
        assigns[:report].should == m
      end

      describe 'and CSV format choice' do
        it 'returns output of TeamNotesReport.render_csv as report' do
          m = 'This is the CSV Team Notes Report Content'
          TeamNotesReport.stub!(:render_csv=>m)

          post :team_notes, {:generate => "Do the report", :report_params => {:format => 'csv'}}, {:user_id => 1}
          assigns[:report].should equal(m)
          assert_template nil # not sure how to do this with an Rspec matcher...

          response.should be_success
          response.body.should equal(m)
        end
      end # CSV

      describe 'and PDF format choice' do
        it 'returns output of TeamNotesReport.render_pdf as report' do
          m = 'This is the PDF Team Notes Report Content'
          TeamNotesReport.stub!(:render_pdf=>m)

          post :team_notes, {:generate => "Do the report", :report_params => {:format => 'pdf'}}, {:user_id => 1}
          assigns[:report].should equal(m)
          assert_template nil # not sure how to do this with an Rspec matcher...

          response.should be_success
          response.body.should equal(m)
        end
      end # PDF
      
    end
  end
end
{'fraction_non_alphanumeric': 0.12185505069470522, 'fraction_numerical': 0.012767555388659407, 'mean_word_length': 2.643638850889193, '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': '2262904', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1511, 'n_words': 463}