Sha256: 20abd48012ee745f8c0c3ccc0f7840f30eeafe3ccc93888a76cb307b6b77ff72

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'helper'

class User
  include Mongoid::Document
  include Mongoid::Document::Flagable
  field :name
end

describe "A Flagable model" do
  let(:user) { User.new(name: 'John Doe') }

  it "should have an add_flag method" do
    user.should respond_to :add_flag
  end

  it "should have an add_flag! method" do
    user.should respond_to :add_flag!
  end

  it "should have a has_flag? method" do
    user.should respond_to :has_flag?
  end

  it "should have a remove_flag method" do
    user.should respond_to :remove_flag
  end

  it "should have a remove_flag! method" do
    user.should respond_to :remove_flag!
  end

  it "should be able to add a flag" do
    flag = "suspended"
    user.add_flag(flag)
    user.has_flag?(flag).should be true
  end

  it "should be able to remove a flag" do
    flag = "suspended"
    user.add_flag(flag)
    user.remove_flag(flag)
    user.has_flag?(flag).should_not be true
  end

  it "should be able to call add_flag multiple times" do
    user.add_flag('suspended')
    user.add_flag('to be removed')
    user.flags.count.should be 2
  end

  it "should only contain unique flags" do
    user.add_flag('suspended')
    user.add_flag('suspended')
    user.flags.count.should be 1
  end

  it "should be able to find flagged users with find_by_flags" do
    user.add_flag!('suspended')
    User.find_by_flags('suspended').first.should eq(user)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-flags-0.0.1 spec/mongoid-flags_spec.rb