Sha256: ad38f94bebf519ca003d254c07ff4d3c780adf5e84532afe5f9d066e33ff7a3d

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

module Prosperity
  describe DashboardGraphsController do
    routes { Prosperity::Engine.routes }

    let(:valid_graph_attributes) do
      { title: "My Graph", period: "month", graph_type: 'line' }
    end

    let!(:valid_dashboard_attributes) do
      { title: "My Dashboard", default: false }
    end

    let(:graph) { Graph.create!(valid_graph_attributes) }
    let(:dashboard) { Dashboard.create!(valid_dashboard_attributes) }
    let(:dashboard_graph) { DashboardGraph.create! graph: graph, dashboard: dashboard }

    describe "POST 'create'" do
      it "associates a graph an a dashboard" do
        expect do 
          post :create, dashboard_id: dashboard.id, graph_id: graph.id
        end.to change(DashboardGraph, :count).by(1)
        dg = DashboardGraph.last
        dg.graph.should == graph
        dg.dashboard.should == dashboard
      end

      it "errors if you try to add the same graph twice" do
        post :create, dashboard_id: dashboard.id, graph_id: graph.id
        post :create, dashboard_id: dashboard.id, graph_id: graph.id
        response.should redirect_to(edit_dashboard_path(dashboard))
        flash[:error].should be_present
      end
    end

    describe "DELETE 'destroy'" do
      it "deassociates a graph an a dashboard" do
        dashboard_graph
        expect do 
          delete :destroy, dashboard_id: dashboard.id, graph_id: graph.id
        end.to change(DashboardGraph, :count).by(-1)
      end

      it "404 when not found" do
        expect do 
          delete :destroy, dashboard_id: dashboard.id, graph_id: graph.id
        end.to raise_exception(ActiveRecord::RecordNotFound)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
prosperity-0.0.9 spec/controllers/prosperity/dashboard_graphs_controller_spec.rb
prosperity-0.0.8 spec/controllers/prosperity/dashboard_graphs_controller_spec.rb