Skip to content

Commit a5d7054

Browse files
author
Andrew Leung and Dariusz Lorenc
committed
Standup controller #show now accepts json request and exposes time zone in IANA format
1 parent d90d927 commit a5d7054

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

app/controllers/standups_controller.rb

+21-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class StandupsController < ApplicationController
22
before_filter :load_standup, only: [:edit, :show, :update, :destroy]
33
around_filter :standup_timezone, only: [:edit, :show, :update, :destroy]
44

5+
56
def create
67
@standup = Standup.create(params[:standup])
78

@@ -18,18 +19,33 @@ def new
1819
end
1920

2021
def index
21-
@standups = Standup.all.sort{ |a,b| a.title.downcase <=> b.title.downcase }
22+
@standups = Standup.all.sort { |a, b| a.title.downcase <=> b.title.downcase }
2223
end
2324

24-
def edit; end
25+
def edit;
26+
end
2527

2628
def show
2729
if @standup
2830
session[:last_visited_standup] = params[:id]
29-
redirect_to standup_items_path(@standup)
31+
respond_to do |format|
32+
format.html {
33+
redirect_to standup_items_path(@standup)
34+
}
35+
format.json {
36+
render json: @standup.to_json(:methods => :time_zone_name_iana)
37+
}
38+
end
3039
else
31-
flash[:error] = "A standup with the ID #{params[:id]} does not exist."
32-
redirect_to standups_path
40+
respond_to do |format|
41+
format.html {
42+
flash[:error] = "A standup with the ID #{params[:id]} does not exist."
43+
redirect_to standups_path
44+
}
45+
format.json {
46+
head :not_found
47+
}
48+
end
3349
end
3450
end
3551

app/models/standup.rb

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def next_standup_date
3333
standup_time
3434
end
3535

36+
def time_zone_name_iana
37+
ActiveSupport::TimeZone.find_tzinfo(self.time_zone_name).identifier
38+
end
39+
3640
def finished_today
3741
standup_time_today < time_zone.now
3842
end

spec/controllers/standups_controller_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@
7979
expect(response.body).to redirect_to standup_items_path(standup)
8080
end
8181

82+
it "renders json and time zone IANA field" do
83+
request.accept = Mime::JSON.to_s
84+
get :show, id: standup.id
85+
expect(response.content_type).to eq(Mime::JSON.to_s)
86+
expect(response.body).to include(standup.time_zone_name_iana)
87+
end
88+
89+
it "returns 404 when standup not found" do
90+
request.accept = Mime::JSON.to_s
91+
get :show, id: 123
92+
expect(response).to be_not_found
93+
end
94+
8295
it 'saves standup id to cookie' do
8396
get :show, id: standup.id
8497
expect(session[:last_visited_standup]).to eq(standup.id.to_s)

0 commit comments

Comments
 (0)