Created
September 21, 2016 10:30
-
-
Save tf/3024227ab358793794282cf52272664a to your computer and use it in GitHub Desktop.
Pageflow `without_password_protection` scopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WithoutPasswordProtectionScopes | |
module Revision | |
extend ActiveSupport::Concern | |
included do | |
scope(:without_password_protection, | |
-> { where('password_protected IS NOT TRUE') }) | |
end | |
end | |
module Entry | |
extend ActiveSupport::Concern | |
included do | |
scope(:published_without_password_protection, | |
-> { | |
joins(:published_revision) | |
.merge(Pageflow::Revision.without_password_protection) | |
}) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe WithoutPasswordProtectionScopes do | |
describe 'Revision.without_password_protection' do | |
it 'includes revision without password_protected flag' do | |
revision = create(:revision) | |
result = Pageflow::Revision.without_password_protection | |
expect(result).to include(revision) | |
end | |
it 'does not include revision with password_protected flag set to true' do | |
revision = create(:revision, password_protected: true) | |
result = Pageflow::Revision.without_password_protection | |
expect(result).not_to include(revision) | |
end | |
it 'includes revision with password_protected flag set to false' do | |
revision = create(:revision, password_protected: false) | |
result = Pageflow::Revision.without_password_protection | |
expect(result).to include(revision) | |
end | |
end | |
describe 'Entry.published_without_password_protection' do | |
it 'includes published entries without password protection' do | |
entry = create(:entry, :published) | |
result = Pageflow::Entry.published_without_password_protection | |
expect(result).to include(entry) | |
end | |
it 'does not include non published entries' do | |
entry = create(:entry) | |
result = Pageflow::Entry.published_without_password_protection | |
expect(result).not_to include(entry) | |
end | |
it 'does not include published entries with password protection' do | |
entry = create(:entry, :published_with_password) | |
result = Pageflow::Entry.published_without_password_protection | |
expect(result).not_to include(entry) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment