Skip to content

Instantly share code, notes, and snippets.

@tf
Created September 21, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tf/3024227ab358793794282cf52272664a to your computer and use it in GitHub Desktop.
Save tf/3024227ab358793794282cf52272664a to your computer and use it in GitHub Desktop.
Pageflow `without_password_protection` scopes
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
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