Skip to content

Commit

Permalink
Merge branch 'release-4.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 2, 2016
2 parents 5ab89a4 + 65273dc commit 682066c
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 25 deletions.
4 changes: 4 additions & 0 deletions lib/nanoc/base/compilation/compiler.rb
Expand Up @@ -98,6 +98,10 @@ def run
end

def load_stores
# FIXME: icky hack to update the dependency store’s list of objects
# (does not include preprocessed objects otherwise)
dependency_store.objects = site.items.to_a + site.layouts.to_a

stores.each(&:load)
end

Expand Down
6 changes: 5 additions & 1 deletion lib/nanoc/base/entities/document.rb
Expand Up @@ -69,7 +69,11 @@ def hash
def ==(other)
other.respond_to?(:identifier) && identifier == other.identifier
end
alias eql? ==

contract C::Any => C::Bool
def eql?(other)
other.is_a?(self.class) && identifier == other.identifier
end
end
end
end
6 changes: 5 additions & 1 deletion lib/nanoc/base/entities/identifier.rb
Expand Up @@ -76,7 +76,11 @@ def ==(other)
false
end
end
alias eql? ==

contract C::Any => C::Bool
def eql?(other)
other.is_a?(self.class) && to_s == other.to_s
end

contract C::None => C::Num
def hash
Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/base/repos/dependency_store.rb
Expand Up @@ -2,7 +2,7 @@ module Nanoc::Int
# @api private
class DependencyStore < ::Nanoc::Int::Store
# @return [Array<Nanoc::Int::Item, Nanoc::Int::Layout>]
attr_reader :objects
attr_accessor :objects

# @param [Array<Nanoc::Int::Item, Nanoc::Int::Layout>] objects
def initialize(objects)
Expand Down
8 changes: 7 additions & 1 deletion lib/nanoc/base/views/item_rep_view.rb
Expand Up @@ -15,7 +15,13 @@ def unwrap
def ==(other)
other.respond_to?(:item) && other.respond_to?(:name) && item == other.item && name == other.name
end
alias eql? ==

# @see Object#eql?
def eql?(other)
other.is_a?(self.class) &&
item.eql?(other.item) &&
name.eql?(other.name)
end

# @see Object#hash
def hash
Expand Down
6 changes: 5 additions & 1 deletion lib/nanoc/base/views/mixins/document_view_mixin.rb
Expand Up @@ -18,7 +18,11 @@ def unwrap
def ==(other)
other.respond_to?(:identifier) && identifier == other.identifier
end
alias eql? ==

# @see Object#eql?
def eql?(other)
other.is_a?(self.class) && identifier.eql?(other.identifier)
end

# @see Object#hash
def hash
Expand Down
20 changes: 16 additions & 4 deletions spec/nanoc/base/entities/identifier_spec.rb
Expand Up @@ -128,8 +128,11 @@
let(:identifier_a) { described_class.new('//foo/bar/', type: :legacy) }
let(:identifier_b) { described_class.new('/foo/bar//', type: :legacy) }

it 'is equal' do
it 'is ==' do
expect(identifier_a).to eq(identifier_b)
end

it 'is eql?' do
expect(identifier_a).to eql(identifier_b)
end
end
Expand All @@ -138,18 +141,24 @@
let(:identifier_a) { described_class.new('//foo/bar/', type: :legacy) }
let(:identifier_b) { '/foo/bar/' }

it 'is equal' do
it 'is ==' do
expect(identifier_a).to eq(identifier_b.to_s)
expect(identifier_a).to eql(identifier_b.to_s)
end

it 'is not eql?' do
expect(identifier_a).not_to eql(identifier_b.to_s)
end
end

context 'comparing with different identifier' do
let(:identifier_a) { described_class.new('//foo/bar/', type: :legacy) }
let(:identifier_b) { described_class.new('/baz/qux//', type: :legacy) }

it 'is not equal' do
it 'is not ==' do
expect(identifier_a).not_to eq(identifier_b)
end

it 'is not eql?' do
expect(identifier_a).not_to eql(identifier_b)
end
end
Expand All @@ -160,6 +169,9 @@

it 'is not equal' do
expect(identifier_a).not_to eq(identifier_b)
end

it 'is not eql?' do
expect(identifier_a).not_to eql(identifier_b)
end
end
Expand Down
33 changes: 24 additions & 9 deletions spec/nanoc/base/views/document_view_spec.rb
Expand Up @@ -33,44 +33,59 @@
context 'comparing with document with same identifier' do
let(:other) { entity_class.new('content', {}, '/asdf/') }

it 'is equal' do
it 'is ==' do
expect(view).to eq(other)
expect(view).to eql(other)
end

it 'is not eql?' do
expect(view).not_to eql(other)
end
end

context 'comparing with document with different identifier' do
let(:other) { entity_class.new('content', {}, '/fdsa/') }

it 'is not equal' do
it 'is not ==' do
expect(view).not_to eq(other)
end

it 'is not eql?' do
expect(view).not_to eql(other)
end
end

context 'comparing with document view with same identifier' do
let(:other) { Nanoc::LayoutView.new(entity_class.new('content', {}, '/asdf/'), nil) }
let(:other) { other_view_class.new(entity_class.new('content', {}, '/asdf/'), nil) }

it 'is equal' do
it 'is ==' do
expect(view).to eq(other)
expect(view).to eql(other)
end

it 'is not eql?' do
expect(view).not_to eql(other)
end
end

context 'comparing with document view with different identifier' do
let(:other) { Nanoc::LayoutView.new(entity_class.new('content', {}, '/fdsa/'), nil) }
let(:other) { other_view_class.new(entity_class.new('content', {}, '/fdsa/'), nil) }

it 'is not equal' do
it 'is not ==' do
expect(view).not_to eq(other)
end

it 'is not eql?' do
expect(view).not_to eql(other)
end
end

context 'comparing with other object' do
let(:other) { nil }

it 'is not equal' do
it 'is not ==' do
expect(view).not_to eq(other)
end

it 'is not eql?' do
expect(view).not_to eql(other)
end
end
Expand Down
24 changes: 18 additions & 6 deletions spec/nanoc/base/views/item_rep_view_spec.rb
Expand Up @@ -32,18 +32,24 @@
let(:other_item) { double(:other_item, identifier: '/foo/') }
let(:other) { double(:other_item_rep, item: other_item, name: :jacques) }

it 'is equal' do
it 'is ==' do
expect(view).to eq(other)
expect(view).to eql(other)
end

it 'is eql?' do
expect(view).not_to eql(other)
end
end

context 'comparing with item rep with different identifier' do
let(:other_item) { double(:other_item, identifier: '/bar/') }
let(:other) { double(:other_item_rep, item: other_item, name: :jacques) }

it 'is not equal' do
it 'is not ==' do
expect(view).not_to eq(other)
end

it 'is not eql?' do
expect(view).not_to eql(other)
end
end
Expand All @@ -52,8 +58,11 @@
let(:other_item) { double(:other_item, identifier: '/foo/') }
let(:other) { double(:other_item_rep, item: other_item, name: :marvin) }

it 'is not equal' do
it 'is not ==' do
expect(view).not_to eq(other)
end

it 'is not eql?' do
expect(view).not_to eql(other)
end
end
Expand All @@ -62,9 +71,12 @@
let(:other_item) { double(:other_item, identifier: '/foo/') }
let(:other) { described_class.new(double(:other_item_rep, item: other_item, name: :jacques), view_context) }

it 'is equal' do
it 'is ==' do
expect(view).to eq(other)
expect(view).to eql(other)
end

it 'is eql?' do
expect(view).not_to eql(other)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/nanoc/base/views/item_view_spec.rb
@@ -1,5 +1,6 @@
describe Nanoc::ItemWithRepsView do
let(:entity_class) { Nanoc::Int::Item }
let(:other_view_class) { Nanoc::LayoutView }
it_behaves_like 'a document view'

let(:view_context) { Nanoc::ViewContext.new(reps: reps, items: items, dependency_tracker: dependency_tracker, compiler: compiler) }
Expand Down
1 change: 1 addition & 0 deletions spec/nanoc/base/views/layout_view_spec.rb
@@ -1,4 +1,5 @@
describe Nanoc::LayoutView do
let(:entity_class) { Nanoc::Int::Layout }
let(:other_view_class) { Nanoc::ItemWithRepsView }
it_behaves_like 'a document view'
end
2 changes: 1 addition & 1 deletion spec/nanoc/helpers/blogging_spec.rb
Expand Up @@ -33,7 +33,7 @@
end

it 'returns the two articles in descending order' do
expect(subject.map(&:identifier)).to eql(['/2/', '/1/'])
expect(subject.map(&:identifier)).to eq(['/2/', '/1/'])
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/nanoc/regressions/gh_885_spec.rb
@@ -0,0 +1,30 @@
describe 'GH-885', site: true, stdio: true do
before do
File.write(
'content/index.html',
"<%= @items['/hello.*'].compiled_content %> - <%= Time.now.to_f %>",
)

File.write('Rules', <<EOS)
preprocess do
items.create('hi!', {}, '/hello.html')
end
compile '/**/*' do
filter :erb
write item.identifier.without_ext + '.html'
end
EOS
end

example do
Nanoc::CLI.run(%w(compile))
before = File.read('output/index.html')

sleep(0.1)
Nanoc::CLI.run(%w(compile))
after = File.read('output/index.html')
expect(after).to eql(before)
expect(after).to match(/\Ahi! - \d+/)
end
end
26 changes: 26 additions & 0 deletions spec/nanoc/regressions/gh_891_spec.rb
@@ -0,0 +1,26 @@
describe 'GH-891', site: true, stdio: true do
before do
File.write('layouts/foo.erb', 'giraffes? <%= yield %>')
File.write('Rules', <<EOS)
preprocess do
items.create('yes!', {}, '/hello.html')
end
compile '/**/*' do
layout '/foo.*'
write item.identifier.without_ext + '.html'
end
layout '/foo.*', :erb
EOS
end

example do
Nanoc::CLI.run(%w(compile))
expect(File.read('output/hello.html')).to include('giraffes?')

File.write('layouts/foo.erb', 'donkeys? <%= yield %>')
Nanoc::CLI.run(%w(compile))
expect(File.read('output/hello.html')).to include('donkeys?')
end
end

0 comments on commit 682066c

Please sign in to comment.