Sha256: 6b399b8830481958a4567a6522adef7eede112d403e1286674ea12401c17ecd1

Contents?: true

Size: 1.52 KB

Versions: 24

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe Ants::SortedRelations do

  context "Having the book The Art of War" do
    let(:book) { Book.new(:title => 'The Art of War') }

    context "written by the authors Lao Zi, Sun Wu and Sun Tzu." do
      before { book.sorted_author_ids = [ Author.create(:name => 'Sun Tzu').id,
                                          Author.create(:name => 'Sun Wu' ).id,
                                          Author.create(:name => 'Lao Zi' ).id ] }
      before { book.save and book.reload }
      before { book.sorted_author_ids = book.author_ids.map { |id| id.to_s }.reverse }

      the("book.sorted_authors.map(&:name)") { should eql ['Lao Zi', 'Sun Wu', 'Sun Tzu'] }
    end
  end

  context "Having the book War and Piece" do
    let(:book) { Book.create(:title => 'War and Piece') }

    context "to have chapters Intro, Part 1, Part 2, Part 3 and The End." do
      before { book.sorted_chapter_ids = [ Chapter.create(:title => 'The End').id,
                                           Chapter.create(:title => 'Part 3').id,
                                           Chapter.create(:title => 'Part 2').id,
                                           Chapter.create(:title => 'Part 1').id,
                                           Chapter.create(:title => 'Intro').id ] }
      before { book.reload }
      before { book.sorted_chapter_ids = book.chapter_ids.map { |id| id.to_s }.reverse }

      the("book.sorted_chapters.map(&:title)") { should eql ['Intro', 'Part 1', 'Part 2', 'Part 3', 'The End'] }
    end
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ants-0.3.14 spec/mongoid/sorted_relations_spec.rb
ants-0.3.13 spec/mongoid/sorted_relations_spec.rb
ants-0.3.12 spec/mongoid/sorted_relations_spec.rb
ants-0.3.11 spec/mongoid/sorted_relations_spec.rb
ants-0.3.10 spec/mongoid/sorted_relations_spec.rb
ants-0.3.9 spec/mongoid/sorted_relations_spec.rb
ants-0.3.5 spec/mongoid/sorted_relations_spec.rb
ants-0.3.4 spec/mongoid/sorted_relations_spec.rb
ants-0.3.3 spec/mongoid/sorted_relations_spec.rb
ants-0.3.2 spec/mongoid/sorted_relations_spec.rb
ants-0.3.1 spec/mongoid/sorted_relations_spec.rb
ants-0.3.0 spec/mongoid/sorted_relations_spec.rb
ants-0.2.8 spec/mongoid/sorted_relations_spec.rb
ants-0.2.7 spec/mongoid/sorted_relations_spec.rb
ants-0.2.6 spec/mongoid/sorted_relations_spec.rb
ants-0.2.5 spec/mongoid/sorted_relations_spec.rb
ants-0.2.4 spec/mongoid/sorted_relations_spec.rb
ants-0.2.3 spec/mongoid/sorted_relations_spec.rb
ants-0.2.2 spec/mongoid/sorted_relations_spec.rb
ants-0.2.1 spec/mongoid/sorted_relations_spec.rb