Sha256: 935018804aafda9b4042a8711283a2d0bf7eb76f9af766bcf08e8f0a7c2dcc61
Contents?: true
Size: 1.78 KB
Versions: 6
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true require 'spec_helper' require "cancan/matchers" describe Spree::ReviewsAbility do describe '.allow_anonymous_reviews?' do it 'depends on Spree::Reviews::Config[:require_login]' do stub_spree_preferences(Spree::Reviews::Config, require_login: false) expect(described_class.allow_anonymous_reviews?).to be true stub_spree_preferences(Spree::Reviews::Config, require_login: true) expect(described_class.allow_anonymous_reviews?).to be false end end context 'permissions' do let(:user_without_email) { double(:user, email: nil) } let(:user_with_email) { double(:user, email: 'a@b.com') } context 'when anonymous reviews are allowed' do before do stub_spree_preferences(Spree::Reviews::Config, require_login: false) end it 'lets anyone create a review or feedback review' do [user_without_email, user_with_email].each do |u| expect(described_class.new(u)).to be_able_to(:create, Spree::Review.new) expect(described_class.new(u)).to be_able_to(:create, Spree::FeedbackReview.new) end end end context 'when anonymous reviews are not allowed' do before do stub_spree_preferences(Spree::Reviews::Config, require_login: true) end it 'only allows users with an email to create a review or feedback review' do expect(described_class.new(user_without_email)).not_to be_able_to(:create, Spree::Review.new) expect(described_class.new(user_without_email)).not_to be_able_to(:create, Spree::FeedbackReview.new) expect(described_class.new(user_with_email)).to be_able_to(:create, Spree::Review.new) expect(described_class.new(user_with_email)).to be_able_to(:create, Spree::FeedbackReview.new) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems