spec/sequencer_spec.rb in alephant-sequencer-0.0.3 vs spec/sequencer_spec.rb in alephant-sequencer-0.0.4
- old
+ new
@@ -36,11 +36,11 @@
table = double()
table.stub(:create)
table.should_receive(:sequence_for).with(ident).and_return(:expected_value)
expect(
- Alephant::Sequencer::Sequencer.new(table, ident).get_last_seen
+ Alephant::Sequencer::Sequencer.new(table, ident, jsonpath).get_last_seen
).to eq(:expected_value)
end
end
describe "#set_last_seen(data)" do
@@ -51,14 +51,22 @@
it "calls set_sequence_for(ident, last_seen)" do
table = double()
table.stub(:create)
table.should_receive(:set_sequence_for).with(ident, last_seen)
- Alephant::Sequencer::Sequencer.new(table, ident).set_last_seen(data)
+ Alephant::Sequencer::Sequencer.new(table, ident, jsonpath).set_last_seen(data)
end
end
+ describe "#sequence_id_from(data)" do
+ subject { Alephant::Sequencer::Sequencer.new(sequence_table, ident, '$.set_sequence_id') }
+ it "should return the id described by the set jsonpath" do
+ msg = Struct.new(:body).new({ "set_sequence_id" => 1 })
+ expect(subject.sequence_id_from msg).to eq(1)
+ end
+ end
+
describe "#sequential?(data, jsonpath)" do
before(:each) do
Alephant::Sequencer::Sequencer.any_instance.stub(:get_last_seen).and_return(1)
data.stub(:body).and_return('sequence_id' => id_value)
@@ -81,10 +89,10 @@
end
end
end
context "jsonpath = nil" do
- let(:jsonpath) { nil }
+ let(:jsonpath) { '$.sequence_id' }
subject { Alephant::Sequencer::Sequencer.new(sequence_table, :ident, jsonpath) }
context "sequential" do
let(:id_value) { 2 }
it "is true" do