<commit_before>require_relative '../../../minitest_helper'

describe Freeboard::DashboardController do

  let(:controller) do
    c = Freeboard::DashboardController.new
    c.stubs(:params).returns params
    c
  end

  let(:params) { {} }

  before do
    Freeboard::Dashboard.delete_all
  end

  describe "index" do
    it "should return the dashboard to the view" do
      dashboard = Object.new
      controller.stubs(:dashboard).returns dashboard
      controller.index
      controller.instance_eval { @dashboard }.must_be_same_as dashboard
    end
  end

  describe "get_board" do
    it "should return the dashboard data as json" do
      dashboard = Struct.new(:data).new Object.new
      controller.stubs(:dashboard).returns dashboard
      controller.expects(:render).with(json: { data: dashboard.data })
      controller.get_board
    end
  end

  describe "dashboard" do

    let(:key) { Object.new }

    before { params[:key] = key }

    describe "no dashboards exists" do

      before do
        Freeboard::Dashboard.stubs(:where)
                            .with(key: key)
                            .returns []
      end
<commit_msg>Test the save board method.<commit_after>require_relative '../../../minitest_helper'

describe Freeboard::DashboardController do

  let(:controller) do
    c = Freeboard::DashboardController.new
    c.stubs(:params).returns params
    c
  end

  let(:params) { {} }

  before do
    Freeboard::Dashboard.delete_all
  end

  describe "index" do
    it "should return the dashboard to the view" do
      dashboard = Object.new
      controller.stubs(:dashboard).returns dashboard
      controller.index
      controller.instance_eval { @dashboard }.must_be_same_as dashboard
    end
  end

  describe "get_board" do
    it "should return the dashboard data as json" do
      dashboard = Struct.new(:data).new Object.new
      controller.stubs(:dashboard).returns dashboard
      controller.expects(:render).with(json: { data: dashboard.data })
      controller.get_board
    end
  end

  describe "save_board" do

    let(:new_data)  { Object.new }
    let(:dashboard) { Struct.new(:data).new Object.new }

    let(:jsonified_data) { Object.new }

    before do
      params[:data] = new_data
      controller.stubs(:dashboard).returns dashboard

      JSON.stubs(:parse).with(new_data).returns jsonified_data

      dashboard.stubs(:save)
      controller.stubs(:render)
    end

    it "should save the jsonified data" do
      json = jsonified_data
      dashboard.expects(:save).with do
        dashboard.data.must_be_same_as json
      end
      controller.save_board
    end

    it "should render the dashboard data as json" do
      controller.expects(:render).with( { json: { data: jsonified_data } } )
      controller.save_board
    end

  end

  describe "dashboard" do

    let(:key) { Object.new }

    before { params[:key] = key }

    describe "no dashboards exists" do

      before do
        Freeboard::Dashboard.stubs(:where)
                            .with(key: key)
                            .returns []
      end

{'fraction_non_alphanumeric': 0.0982546864899806, 'fraction_numerical': 0.0, 'mean_word_length': 2.5331050228310503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5010010', 'n_tokens_mistral': 920, 'n_tokens_neox': 894, 'n_words': 225}