Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 71b7b71030
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (42 sloc) 1.472 kb
require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + '/nested_set_behavior'
class Directory < ActiveRecord::Base
acts_as_nested_set :left => :lft, :right => :rgt
validates_presence_of :name
end
describe Directory do
def invalid_attributes(options = {})
return { }.merge(options)
end
def valid_attributes(options = {})
$directory_no = $directory_no ? $directory_no + 1 : 0
return { :name => "directory#{$directory_no}" }.merge(options)
end
before do
@model = Directory
@instance = @model.new
end
it_should_behave_like "all nested set models"
it "should throw an error when attempting to assign lft directly" do
lambda {
@instance.lft = 42
}.should raise_error(EvenBetterNestedSet::IllegalAssignmentError)
@instance.lft.should_not == 42
end
it "should throw an error when attempting to assign rgt directly" do
lambda {
@instance.rgt = 42
}.should raise_error(EvenBetterNestedSet::IllegalAssignmentError)
@instance.rgt.should_not == 42
end
it "should throw an error when mass assigning to lft" do
lambda {
@model.new(valid_attributes(:lft => 1))
}.should raise_error(EvenBetterNestedSet::IllegalAssignmentError)
end
it "should throw an error when mass assigning to rgt" do
lambda {
@model.new(valid_attributes(:rgt => 1))
}.should raise_error(EvenBetterNestedSet::IllegalAssignmentError)
end
end
Jump to Line
Something went wrong with that request. Please try again.