diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index e1f39ea0d..09e6a9900 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -5,7 +5,8 @@ describe Comment do let(:comment) { build(:comment) } it_behaves_like "public_voters_stats" - + it_behaves_like "has_public_author" + it "is valid" do expect(comment).to be_valid end diff --git a/spec/models/concerns/has_public_author_spec.rb b/spec/models/concerns/has_public_author_spec.rb new file mode 100644 index 000000000..a5a9c2811 --- /dev/null +++ b/spec/models/concerns/has_public_author_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +shared_examples_for 'has_public_author' do + let(:model) { described_class } + + describe 'public_author' do + it "returns author if author's activity is public" do + author = create(:user, public_activity: true) + authored_element = create(model.to_s.underscore.to_sym, author: author) + + expect(authored_element.public_author).to eq(author) + end + + it "returns nil if author's activity is private" do + author = create(:user, public_activity: false) + authored_element = create(model.to_s.underscore.to_sym, author: author) + + expect(authored_element.public_author).to be_nil + end + end +end diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 7c40e63fe..4db0e5f0a 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -5,7 +5,8 @@ describe Debate do let(:debate) { build(:debate) } it_behaves_like "public_voters_stats" - + it_behaves_like "has_public_author" + it "should be valid" do expect(debate).to be_valid end diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 77eb3e358..08ed6b384 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -5,6 +5,7 @@ describe Proposal do let(:proposal) { build(:proposal) } it_behaves_like "public_voters_stats" + it_behaves_like "has_public_author" it "should be valid" do expect(proposal).to be_valid