Sha256: 67ab4da65f0a37a4e08d8e0bfa17cbaeb1940866309a26e82d8a0f8f04f0eaa8

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe GreenFlag::Admin::FeaturesController do
  let(:feature) { GreenFlag::Feature.create(code: 'foo') }

  describe '#index' do
    it 'is successful' do
      get :index
      expect(response).to be_success
    end
  end  

  describe '#show' do
    it 'is successful' do
      get :show, :id => feature.id
      expect(response).to be_success
    end
  end

  describe "#destroy" do
    subject { delete :destroy, id: feature.id }

    it "redirects to the index action" do
      expect(subject).to redirect_to action: :index
    end

    context "when the feature can be deleted" do
      before(:each) do
        5.times do
          FactoryGirl.create(:green_flag_rule, feature_id: feature.id)
          FactoryGirl.create(:green_flag_feature_event, feature_id: feature.id)
          FactoryGirl.create(:green_flag_feature_decision, feature_id: feature.id)
        end

        subject
      end

      it "deletes the feature" do
        expect(GreenFlag::Feature.find_by_id(feature.id)).to be_nil
      end

      it "deletes the feature's rules" do
        expect(GreenFlag::Rule.where(feature_id: feature.id)).to eq []
      end

      it "deletes the feature's events" do
        expect(GreenFlag::FeatureEvent.where(feature_id: feature.id)).to eq []
      end

      it "deletes the feature's feature decisions" do
        expect(GreenFlag::FeatureDecision.where(feature_id: feature.id)).to eq []
      end

      it "sets a successful flash notice" do
        expect(flash[:notice]).to eq "Feature \"#{feature.code}\" has been \
successfully deleted."
      end
    end

    context "when the feature cannot be found" do
      it "sets a flash error indicating the error" do
        feature.destroy

        subject

        expect(flash[:error]).to eq "The feature could not be found."
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
green_flag-0.4.0 spec/controllers/admin/features_controller_spec.rb
green_flag-0.3.0 spec/controllers/admin/features_controller_spec.rb