Sha256: 5cbae1366d5157d252dbdae3c4c05e3527a64018c3914352ef7b63aa883de3d7

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

require 'rails_helper'

module Kawara
  RSpec.describe TagsController, type: :controller do
    let(:site) { create :opened_site_a }

    routes { Kawara::Engine.routes }

    describe 'GET #index' do
      subject { get :index }

      before { subject }

      context 'when there is no tag' do
        it { expect(response).to render_template(:index) }
        it { expect(response).to have_http_status(:success) }
        it { expect(assigns(:tags)).to match_array(Kawara::Tag.none) }
      end

    end

    describe 'GET #show' do
      subject { get :show, id: id }

      let(:tag) { create :kawara_tag, site: site }
      let(:tag_with_published_articles) { create :kawara_tag_with_published_articles, site: site }

      context 'when there are related articles' do
        let(:id) { tag_with_published_articles.id }

        before { subject }

        it { expect(response).to render_template(:show) }
        it { expect(response).to have_http_status(:success) }
        it { expect(assigns(:articles)).to match(tag_with_published_articles.articles_latest) }
      end

      context 'when there are no related articles' do
        let(:id) { tag.id }

        before { subject }

        it { expect(response).to render_template(:show) }
        it { expect(response).to have_http_status(:success) }
        it { expect(assigns(:articles)).to match Kawara::Article.none }
      end

      context 'when there are no tags' do
        let(:id) { 1 }
        it { expect{subject}.to raise_error(ActiveRecord::RecordNotFound) }
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kawara-0.3.2 spec/controllers/kawara/tags_controller_spec.rb
kawara-0.3.1 spec/controllers/kawara/tags_controller_spec.rb
kawara-0.3.0 spec/controllers/kawara/tags_controller_spec.rb