2014-08-30 17:38:47 +00:00
|
|
|
require 'rails_helper'
|
2013-06-13 20:26:27 +00:00
|
|
|
|
|
|
|
describe ViewCounter do
|
2013-09-25 14:58:44 +00:00
|
|
|
let(:view_counter) { described_class.new }
|
2013-06-13 20:26:27 +00:00
|
|
|
|
|
|
|
describe '#increment' do
|
2013-09-25 14:58:44 +00:00
|
|
|
let(:asciicast) { create(:asciicast) }
|
|
|
|
let(:storage) { {} }
|
|
|
|
|
|
|
|
subject { view_counter.increment(asciicast, storage) }
|
|
|
|
|
2013-06-13 20:26:27 +00:00
|
|
|
context "when called for the first time" do
|
|
|
|
it "increments the views_count" do
|
2013-09-25 14:58:44 +00:00
|
|
|
expect { subject }.to change(asciicast, :views_count).by(1)
|
2013-06-13 20:26:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when called for the second time" do
|
|
|
|
before do
|
2013-09-25 14:58:44 +00:00
|
|
|
subject
|
2013-06-13 20:26:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't increment the views_count" do
|
2013-09-25 14:58:44 +00:00
|
|
|
expect { subject }.not_to change(asciicast, :views_count)
|
2013-06-13 20:26:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|