spec/lita/handlers/totems_spec.rb in lita-totems-0.1.0 vs spec/lita/handlers/totems_spec.rb in lita-totems-0.2.0
- old
+ new
@@ -95,53 +95,96 @@
send_message("totems add chicken", as: user_generator.generate)
send_message("totems add chicken", as: user_generator.generate)
end
it "adds user to the queue" do
send_message("totems add chicken", as: carl)
- expect(replies.last).to eq('Carl, you are 2nd in line for totem "chicken".')
+ expect(replies.last).to eq('Carl, you are #2 in line for totem "chicken".')
end
end
+ context "when the user is already holding the totem" do
+ before do
+ send_message("totems add chicken", as: carl)
+ end
+ it "returns an error message" do
+ send_message("totems add chicken", as: carl)
+ expect(replies.last).to eq('Error: you already have the totem "chicken".')
+ end
+ end
+
+ context "when the user is already in line for the totem" do
+ before do
+ send_message("totems add chicken", as: another_user)
+ send_message("totems add chicken", as: carl)
+ end
+ it "returns an error message" do
+ send_message("totems add chicken", as: carl)
+ expect(replies.last).to eq('Error: you are already in the queue for "chicken".')
+ end
+ end
+
end
context "when the totem doesn't exist" do
it "lets user know" do
send_message("totems add chicken", as: carl)
expect(replies.last).to eq('Error: there is no totem "chicken".')
end
-
end
-
end
describe "yield" do
before do
send_message("totems create chicken")
+ send_message("totems create duck")
end
context "when user has one totem" do
before do
- send_message("totems add chicken", as: carl)
+ Timecop.freeze("2014-03-01 11:00:00") do
+ send_message("totems add chicken", as: carl)
+ end
end
context "someone else is in line" do
before do
- send_message("totems add chicken", as: another_user)
+ Timecop.freeze("2014-03-01 12:00:00") do
+ send_message("totems add chicken", as: another_user)
+ send_message("totems add chicken", as: yet_another_user)
+ end
end
it "yields that totem, gives to the next person in line" do
expect(robot).to receive(:send_messages) do |target, message|
- expect(target.id).to eq(another_user.id)
+ expect(target.user.id).to eq(another_user.id)
expect(message).to eq(%{You are now in possession of totem "chicken."})
end
send_message("totems yield", as: carl)
# todo: check for message to other user
- expect(replies.last).to eq("You have yielded the totem to #{another_user.id}.")
+ expect(replies.last).to eq("You have yielded the totem to #{another_user.name}.")
end
+ it "updates the waiting since value for the new holder" do
+ Timecop.freeze("2014-03-01 13:00:00") do
+ send_message("totems info chicken")
+ expect(replies.last).to eq <<-END
+1. Carl (held for 2h)
+2. Test User (waiting for 1h)
+3. person_2 (waiting for 1h)
+ END
+ send_message("totems yield", as: carl)
+ send_message("totems info chicken")
+ expect(replies.last).to eq <<-END
+1. Test User (held for 0s)
+2. person_2 (waiting for 1h)
+ END
+ end
+ end
end
context "nobody else is in line" do
- it "yields the totem" do
+ it "yields the totem and clears the owning_user_id" do
send_message("totems yield", as: carl)
expect(replies.last).to eq(%{You have yielded the "chicken" totem.})
+ send_message("totems info chicken")
+ expect(replies.last).to eq ""
end
end
end
context "when user has no totems" do
it "sends an error" do
@@ -157,11 +200,11 @@
end
context "when specifying a totem" do
context "user doesn't have that totem" do
it "sends error message" do
send_message("totems yield duck", as: carl)
- expect(replies.last).to eq(%{Error: You don't own the "duck" totem.})
+ expect(replies.last).to eq(%{Error: You don't own and aren't waiting for the "duck" totem.})
end
end
context "user has that totem" do
it "yields totem" do
send_message("totems yield chicken", as: carl)
@@ -171,40 +214,153 @@
end
end
context "when not specifying a totem" do
it "sends a message about which totem it can yield" do
send_message("totems yield", as: carl)
- expect(replies.last).to eq(%{You must specify a totem to yield. Totems you own: ["chicken", "#{other_totem}"]})
+ expect(replies.last).to eq(%{You must specify a totem to yield. Totems you own: ["chicken", "#{other_totem}"]. Totems you are in line for: [].})
end
end
+ end
+ context "when the user is in line for a single totem" do
+ before do
+ Timecop.freeze("2014-03-02 13:00:00") do
+ send_message("totems add chicken", as: another_user)
+ send_message("totems add chicken", as: carl)
+ end
+ end
+ context "when specifying a totem" do
+ context "user is not in line for that totem" do
+ it "sends error message" do
+ send_message("totems yield duck", as: carl)
+ expect(replies.last).to eq(%{Error: You don't own and aren't waiting for the "duck" totem.})
+ end
+ end
+ context "user is in line for that totem" do
+ it "yields totem and does not update holder" do
+ Timecop.freeze("2014-03-02 14:00:00") do
+ send_message("totems yield chicken", as: carl)
+ expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
+ send_message("totems info chicken")
+ expect(replies.last).to eq("1. Test User (held for 1h)\n")
+ end
+ end
+ end
+ end
+ context "when not specifying a totem" do
+ it "yields totem and does not update holder" do
+ Timecop.freeze("2014-03-02 14:00:00") do
+ send_message("totems yield", as: carl)
+ expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
+ send_message("totems info chicken")
+ expect(replies.last).to eq("1. Test User (held for 1h)\n")
+ end
+ end
+ end
+ end
+ context "when the user is in line for multiple totems" do
+ before do
+ Timecop.freeze("2014-03-02 13:00:00") do
+ send_message("totems add chicken", as: another_user)
+ send_message("totems add chicken", as: carl)
+ send_message("totems add chicken", as: yet_another_user)
+ send_message("totems add duck", as: yet_another_user)
+ send_message("totems add duck", as: carl)
+ end
+ end
+ context "when specifying a totem" do
+ context "user is in line for that totem" do
+ it "yields totem and does not update holder" do
+ Timecop.freeze("2014-03-02 14:00:00") do
+ send_message("totems yield chicken", as: carl)
+ expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
+ send_message("totems info chicken")
+ expect(replies.last).to eq("1. Test User (held for 1h)\n2. person_2 (waiting for 1h)\n")
+ end
+ end
+ end
+ end
+ context "when not specifying a totem" do
+ it "sends error message" do
+ Timecop.freeze("2014-03-02 14:00:00") do
+ send_message("totems yield", as: carl)
+ expect(replies.last).to eq(%{You must specify a totem to yield. Totems you own: []. Totems you are in line for: ["chicken", "duck"].})
+ end
+ end
+ end
end
+ context "when the user is in line for a totem and has another totem" do
+ before do
+ Timecop.freeze("2014-03-02 13:00:00") do
+ send_message("totems add chicken", as: another_user)
+ send_message("totems add chicken", as: carl)
+ send_message("totems add chicken", as: yet_another_user)
+ send_message("totems add duck", as: carl)
+ send_message("totems add duck", as: another_user)
+ end
+ end
+ context "when specifying a totem" do
+ context "user is in line for that totem" do
+ it "yields totem and does not update holder" do
+ Timecop.freeze("2014-03-02 14:00:00") do
+ send_message("totems yield chicken", as: carl)
+ expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
+ send_message("totems info chicken")
+ expect(replies.last).to eq("1. Test User (held for 1h)\n2. person_2 (waiting for 1h)\n")
+ end
+ end
+ end
+ end
+ context "when not specifying a totem" do
+ it "sends error message" do
+ Timecop.freeze("2014-03-02 14:00:00") do
+ send_message("totems yield", as: carl)
+ expect(replies.last).to eq(%{You must specify a totem to yield. Totems you own: ["duck"]. Totems you are in line for: ["chicken"].})
+ end
+ end
+ end
+ end
end
+
+
describe "kick" do
before do
send_message("totems create chicken")
end
- context "there is a user owning the totem" do
+ context "there is a user owning the totem and somebody else waiting for it" do
before do
send_message("totems add chicken", as: another_user)
send_message("totems add chicken", as: carl)
end
it "should notify that user that she has been kicked" do
expect(robot).to receive(:send_messages) do |target, message|
- expect(target.id).to eq(another_user.id)
+ expect(target.user.id).to eq(another_user.id)
expect(message).to eq(%{You have been kicked from totem "chicken".})
end
send_message("totems kick chicken")
-
end
it "should notify next user in line that she now has the totem" do
send_message("totems kick chicken")
expect(replies.last).to eq(%{You are now in possession of totem "chicken".})
end
+ end
+ context "there is a user owning the totem" do
+ before do
+ send_message("totems add chicken", as: carl)
+ end
+ it "should notify that user that she has been kicked and clear the owning_user_id" do
+ expect(robot).to receive(:send_messages) do |target, message|
+ expect(target.user.id).to eq(carl.id)
+ expect(message).to eq(%{You have been kicked from totem "chicken".})
+ end
+ send_message("totems kick chicken")
+ send_message("totems info chicken")
+ expect(replies.last).to eq ""
+ end
end
context "nobody owns that totem" do
it "sends an error" do
send_message("totems kick chicken")
@@ -213,45 +369,52 @@
end
end
describe "info" do
before do
- send_message("totems create chicken")
- send_message("totems create duck")
- send_message("totems create ball")
- send_message("totems add chicken", as: carl)
- send_message("totems add chicken", as: another_user)
- send_message("totems add duck", as: yet_another_user)
- send_message("totems add duck", as: carl)
-
+ Timecop.freeze("2014-03-01 12:00:00") do
+ send_message("totems create chicken")
+ send_message("totems create duck")
+ send_message("totems create ball")
+ send_message("totems add chicken", as: carl)
+ send_message("totems add chicken", as: another_user)
+ send_message("totems add chicken", as: yet_another_user)
+ send_message("totems add duck", as: yet_another_user)
+ send_message("totems add duck", as: carl)
+ end
end
context "totem is passed" do
it "shows info for just that totem" do
- send_message("totems info chicken")
- expect(replies.last).to eq <<-END
-1. User id #{carl.id}
-2. User id #{another_user.id}
- END
-
+ Timecop.freeze("2014-03-01 13:00:00") do
+ send_message("totems info chicken")
+ expect(replies.last).to eq <<-END
+1. Carl (held for 1h)
+2. Test User (waiting for 1h)
+3. person_2 (waiting for 1h)
+ END
+ end
end
end
context "totem isn't passed" do
it "shows info for all totems" do
- send_message("totems info")
- expect(replies.last).to include <<-END
+ Timecop.freeze("2014-03-02 13:00:00") do
+ send_message("totems info")
+ expect(replies.last).to include <<-END
- chicken
- 1. User id #{carl.id}
- 2. User id #{another_user.id}
- END
- expect(replies.last).to include <<-END
+ 1. Carl (held for 1d 1h)
+ 2. Test User (waiting for 1d 1h)
+ 3. person_2 (waiting for 1d 1h)
+ END
+ expect(replies.last).to include <<-END
- duck
- 1. User id #{yet_another_user.id}
- 2. User id #{carl.id}
- END
- expect(replies.last).to include <<-END
+ 1. person_2 (held for 1d 1h)
+ 2. Carl (waiting for 1d 1h)
+ END
+ expect(replies.last).to include <<-END
- ball
- END
+ END
+ end
end
end
end