Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the time of a game #91

Merged
merged 10 commits into from
Jul 24, 2019
93 changes: 48 additions & 45 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
source "https://rubygems.org"
# frozen_string_literal: true

ruby "2.6.0"
source 'https://rubygems.org'

gem "autoprefixer-rails"
gem "bourbon", "~> 4.2.0"
gem "coffee-rails", "~> 4.1.0"
gem "delayed_job_active_record"
gem "flutie"
gem "high_voltage"
gem "jquery-rails"
gem "neat", "~> 1.7.0"
gem "newrelic_rpm", ">= 3.9.8"
gem "normalize-rails", "~> 3.0.0"
gem "pg"
gem "puma"
gem "rack-canonical-host"
gem "rails", "~> 4.2"
gem "recipient_interceptor"
gem "sass-rails", "~> 5.0"
gem "simple_form"
gem "title"
gem "uglifier"
gem "telegram-bot-ruby"
gem "leaflet-rails"
ruby '2.6.0'

gem 'autoprefixer-rails'
gem 'bourbon', '~> 4.2.0'
gem 'chronic'
gem 'coffee-rails', '~> 4.1.0'
gem 'delayed_job_active_record'
gem 'flutie'
gem 'high_voltage'
gem 'jquery-rails'
gem 'leaflet-rails'
gem 'neat', '~> 1.7.0'
gem 'newrelic_rpm', '>= 3.9.8'
gem 'normalize-rails', '~> 3.0.0'
gem 'pg'
gem 'puma'
gem 'rack-canonical-host'
gem 'rails', '~> 4.2'
gem 'recipient_interceptor'
gem 'sass-rails', '~> 5.0'
gem 'simple_form'
gem 'telegram-bot-ruby'
gem 'title'
gem 'uglifier'

group :development do
gem "quiet_assets"
gem "refills"
gem "spring"
gem "spring-commands-rspec"
gem "web-console"
gem 'quiet_assets'
gem 'refills'
gem 'spring'
gem 'spring-commands-rspec'
gem 'web-console'
end

group :development, :test do
gem "awesome_print"
gem "bullet"
gem "bundler-audit", require: false
gem "dotenv-rails"
gem "factory_girl_rails"
gem "pry-byebug"
gem "pry-rails"
gem "rspec-rails", "~> 3.4.0"
gem 'awesome_print'
gem 'bullet'
gem 'bundler-audit', require: false
gem 'dotenv-rails'
gem 'factory_girl_rails'
gem 'pry-byebug'
gem 'pry-rails'
gem 'rspec-rails', '~> 3.4.0'
end

group :test do
gem "capybara-webkit"
gem "database_cleaner"
gem "formulaic"
gem "launchy"
gem "shoulda-matchers"
gem "simplecov", require: false
gem "timecop"
gem "webmock"
gem 'capybara-webkit'
gem 'database_cleaner'
gem 'formulaic'
gem 'launchy'
gem 'shoulda-matchers'
gem 'simplecov', require: false
gem 'timecop'
gem 'webmock'
end

group :staging, :production do
gem "rack-timeout"
gem 'rack-timeout'
end
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ GEM
capybara-webkit (1.15.1)
capybara (>= 2.3, < 4.0)
json
chronic (0.10.2)
coderay (1.1.1)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
Expand Down Expand Up @@ -282,6 +283,7 @@ DEPENDENCIES
bullet
bundler-audit
capybara-webkit
chronic
coffee-rails (~> 4.1.0)
database_cleaner
delayed_job_active_record
Expand Down
3 changes: 1 addition & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ en:
/create_game to start a new game
/archive_game to archive the current game
/leave to leave a game that you joined
/add_time to add a time to the current game
/add_date to add a date to the current game
/set_time to add a time to the current game
whatever: "Whatever, @%{username}"
no_game: "There's no active game, @%{username}"
date: "The date is set to %{date}"
Expand Down
3 changes: 1 addition & 2 deletions db/migrate/20190702161748_add_hour_and_minutes_to_game.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class AddHourAndMinutesToGame < ActiveRecord::Migration
def change
add_column :games, :time, :string
add_column :games, :date, :string
add_column :games, :datetime, :datetime
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
t.datetime "updated_at", null: false
t.uuid "uuid", default: "uuid_generate_v4()"
t.datetime "archived_at"
t.string "time"
t.string "date"
t.datetime "datetime"
end

create_table "locations", force: :cascade do |t|
Expand Down
6 changes: 2 additions & 4 deletions lib/pickup_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ def handle_text(message)
PickupBot::Commands::Join.run(telegram_bot, message)
when /leave/
PickupBot::Commands::Leave.run(telegram_bot, message)
when /add_time/
PickupBot::Commands::AddTime.run(telegram_bot, message)
when /add_date/
PickupBot::Commands::AddDate.run(telegram_bot, message)
when /set_time/
PickupBot::Commands::SetTime.run(telegram_bot, message)
else
PickupBot::Commands::Error.run(telegram_bot, message, exception)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/pickup_bot/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ module PickupBot::Commands
require 'pickup_bot/commands/leave'
require 'pickup_bot/commands/set_location'
require 'pickup_bot/commands/status'
require 'pickup_bot/commands/add_time'
require 'pickup_bot/commands/add_date'
require 'pickup_bot/commands/set_time'
86 changes: 0 additions & 86 deletions lib/pickup_bot/commands/add_date.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module PickupBot::Commands
class AddTime
class SetTime
def self.run(telegram_bot, message)
new(telegram_bot, message).run
end
Expand All @@ -10,17 +10,10 @@ def initialize(telegram_bot, message)
end

def run
if game_exists? && time.present?
current_game.update(time: time)
if game_date?
# telegram_bot.api.send_message(
# chat_id: message.chat.id,
# text: I18n.t("bot.date_and_time", username: username, date: parse_date, time: "#{time.hour}:#{time.minute}")
# )
else
if game_exists? && current_game.update(datetime: datetime)
telegram_bot.api.send_message(
chat_id: message.chat.id,
text: I18n.t("bot.time", time: time)
text: I18n.t("bot.date")
)
end
else
Expand Down Expand Up @@ -59,11 +52,10 @@ def game_date?
current_game.blank?
end

def time
text = @message.text
def datetime
@message.text
.then { |x| x.split(" ", 2).last.strip }
.then { |x| Time.parse(x) }
.then { |time| "#{format('%02d', time.hour)}:#{format('%02d', time.min)}" }
.then { |x| Chronic.parse(x) }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'telegram/bot'
require 'pickup_bot'

feature "add time to a game" do
feature "sit time to a game" do
let(:bot) { Telegram::Bot::Client.new('fake-token') }
let(:pickup_bot) { PickupBot.new(bot) }
let(:telegram_user) { Telegram::Bot::Types::User.new(user_params) }
Expand All @@ -15,7 +15,7 @@

context "no game currently exists" do
scenario "player tries to add a time" do
message = Telegram::Bot::Types::Message.new(message_params('/add_time 06:00'))
message = Telegram::Bot::Types::Message.new(message_params('/set_time 06:00'))

pickup_bot.run(message)

Expand All @@ -32,9 +32,30 @@
end

context "an active game exists" do
before do
Game.create(chat_id: fake_chat_id, required_players: 5)
end

scenario "new player joins game, a new player is created" do
message = Telegram::Bot::Types::Message.new(message_params('/set_time 06:00 '))

pickup_bot.run(message)

expect(a_request(:post, "https://api.telegram.org/botfake-token/sendMessage").
with(body: {
"chat_id" => "123",
"text" => I18n.t(
"bot.time",
username: user_params[:username],
time: "06:00"
)
}
)).to have_been_made.times(1)
expect(Game.last.time).to eq "06:00"
end

scenario "new player joins game, a new player is created" do
fatboypunk marked this conversation as resolved.
Show resolved Hide resolved
message = Telegram::Bot::Types::Message.new(message_params('/add_time 06:00 '))
game = Game.create(chat_id: fake_chat_id, required_players: 5)
message = Telegram::Bot::Types::Message.new(message_params('/set_time next week'))

pickup_bot.run(message)

Expand Down