Sha256: 124bc6ebfa696b30b8dff3e3c6fcfccbe43adf5407c49d85a736c4b72d33b698

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe Spree::Admin::ReviewsController do
  stub_authorization!

  let(:product) { create(:product) }
  let(:review) { create(:review, approved: false) }

  before do
    user = create(:admin_user)
    controller.stub(try_spree_current_user: user)
  end

  context '#index' do
    it 'list reviews' do
      reviews = [
        create(:review, product: product),
        create(:review, product: product)
      ]
      spree_get :index, product_id: product.slug
      assigns[:reviews].should =~ reviews
    end
  end

  context '#approve' do
    it 'show notice message when approved' do
      review.update_attribute(:approved, true)
      spree_get :approve, id: review.id
      response.should redirect_to spree.admin_reviews_path
      flash[:notice].should eq Spree.t(:info_approve_review)
    end

    it 'show error message when not approved' do
      Spree::Review.any_instance.stub(:update_attribute).and_return(false)
      spree_get :approve, id: review.id
      flash[:error].should eq Spree.t(:error_approve_review)
    end
  end

  context '#edit' do
    specify do
      spree_get :edit, id: review.id
      response.status.should eq(200)
    end

    context 'when product is nil' do
      before do
        review.product = nil
        review.save!
      end

      it 'flash error' do
        spree_get :edit, id: review.id
        flash[:error].should eq Spree.t(:error_no_product)
      end

      it 'redirect to admin-reviews page' do
        spree_get :edit, id: review.id
        response.should redirect_to spree.admin_reviews_path
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
solidus_reviews-1.0.0 spec/controllers/admin/reviews_controller_spec.rb
jiffyshirts_spree_reviews-2.3.1.2 spec/controllers/admin/reviews_controller_spec.rb
jiffyshirts_spree_reviews-2.3.1.1 spec/controllers/admin/reviews_controller_spec.rb