Skip to content

Commit caa7457

Browse files
author
Austin Schneider
committed
refactor out User object until i figure out a better solution
1 parent bc66e38 commit caa7457

13 files changed

+90
-114
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ gem 'haml-rails', '0.3.4'
66
gem 'jquery-rails', '1.0.16'
77
gem 'formalize-rails', '0.0.5'
88
gem 'httparty', '0.8.1'
9-
gem 'decent_exposure', '1.0.1'
109
gem 'squeel', '0.9.3'
1110
gem 'resque', git: 'git://github.com/defunkt/resque.git' # waiting for 1.19.1
1211
gem 'resque-scheduler', '1.9.9'

Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ GEM
7575
cucumber (>= 1.1.1)
7676
nokogiri (>= 1.5.0)
7777
database_cleaner (0.6.7)
78-
decent_exposure (1.0.1)
7978
diff-lcs (1.1.3)
8079
erubis (2.7.0)
8180
execjs (1.2.9)
@@ -248,7 +247,6 @@ DEPENDENCIES
248247
coffee-rails (~> 3.1.1)
249248
cucumber-rails (~> 1.2.0)
250249
database_cleaner (~> 0.6.7)
251-
decent_exposure (= 1.0.1)
252250
factory_girl_rails (~> 1.3.0)
253251
faker (~> 1.0.1)
254252
foreman (>= 0.25.0)

app/controllers/alerts_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ def create
99
respond_with alert, location: alerts_url
1010
end
1111

12+
##################################################
13+
1214
# TODO: test
1315
def alert
14-
@alert ||= current_user.build_alert(params)
16+
@alert ||= begin
17+
attrs = params[:alert] || {}
18+
attrs[:location_id] = params[:location_id] if params[:location_id].present?
19+
Alert.new attrs
20+
end
1521
end
1622

1723
end

app/controllers/application_controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ class ApplicationController < ActionController::Base
22

33
protect_from_forgery
44

5-
expose(:current_user) { User.new }
6-
75
end

app/controllers/email_callbacks_controller.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ class EmailCallbacksController < ApplicationController
22

33
respond_to :html
44

5-
expose :email_callback
5+
helper_method :email_callback
66

77
def create
8-
current_user.save_email_callback email_callback
8+
email_callback.save
99
respond_with email_callback, location: email_callbacks_url
1010
end
1111

1212
def update
1313
email_callback.attributes = params[:email_callback]
14-
current_user.save_email_callback email_callback
14+
email_callback.save
1515
respond_with email_callback, location: email_callbacks_url
1616
end
1717

@@ -20,4 +20,17 @@ def destroy
2020
respond_with email_callback
2121
end
2222

23+
##################################################
24+
25+
# TODO: test
26+
def email_callback
27+
@email_callback ||= begin
28+
if params[:id]
29+
EmailCallback.find params[:id]
30+
else
31+
EmailCallback.new params[:email_callback]
32+
end
33+
end
34+
end
35+
2336
end

app/controllers/locations_controller.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ class LocationsController < ApplicationController
22

33
respond_to :html
44

5-
expose :location
5+
helper_method :location
66

77
def create
8-
current_user.save_location location
8+
location.save_and_schedule_ping!
99
respond_with location
1010
end
1111

1212
def update
1313
location.attributes = params[:location]
14-
current_user.save_location location
14+
location.save_and_schedule_ping!
1515
respond_with location
1616
end
1717

@@ -20,4 +20,17 @@ def destroy
2020
respond_with location
2121
end
2222

23+
##################################################
24+
25+
# TODO: test
26+
def location
27+
@location ||= begin
28+
if params[:id]
29+
Location.find params[:id]
30+
else
31+
Location.new params[:location]
32+
end
33+
end
34+
end
35+
2336
end

lib/pinger/location.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def http_method=(value)
3434
self[:http_method] = value ? value.to_s.downcase : nil
3535
end
3636

37+
# TODO: test
38+
def save_and_schedule_ping!
39+
transaction { schedule_ping! if save }
40+
end
41+
3742
def schedule_ping!
3843
last_ping_at = pings.order { performed_at.desc }.first.try :performed_at
3944
next_ping_to_schedule.schedule! ((last_ping_at || Time.now) + seconds)

lib/pinger/user.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

spec/controllers/alerts_controller_spec.rb

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,47 @@
22

33
describe AlertsController do
44

5-
describe "POST create" do
6-
before { controller.stub(:respond_with) { controller.render text: '' } }
5+
describe "collection actions" do
6+
subject { controller }
77

8-
it "saves the alert" do
9-
controller.alert.should_receive(:save)
10-
post :create
8+
describe "POST create" do
9+
before { subject.stub(:respond_with) { subject.render text: '' } }
10+
11+
it "saves the alert" do
12+
subject.alert.should_receive(:save)
13+
post :create
14+
end
15+
16+
it "tells the controller to respond with the alert" do
17+
subject.should_receive(:respond_with).with subject.alert,
18+
location: alerts_url
19+
post :create
20+
end
1121
end
22+
end
23+
24+
describe "instance methods" do
25+
subject { controller }
26+
27+
describe "alert" do
28+
[
29+
[{:location_id => '234'}, {:location_id => '234'}],
30+
[{:location_id => ''}, {}],
31+
[{:location_id => nil}, {}],
32+
[{}, {}],
33+
[{:alert => {:foo => 'bar'}}, {:foo => 'bar'}],
34+
[{:alert => {:foo => 'bar'}, :location_id => 'foo'}, {:foo => 'bar', :location_id => 'foo'}]
35+
].each do |params, attrs|
36+
context "when the params is #{params.inspect}" do
37+
before do
38+
@alert = mock(Alert)
39+
subject.stub(:params) { params }
40+
Alert.stub(:new) { |args| @alert if args == attrs }
41+
end
1242

13-
it "tells the controller to respond with the alert" do
14-
controller.should_receive(:respond_with).with controller.alert,
15-
location: alerts_url
16-
post :create
43+
it { subject.alert.should == @alert }
44+
end
45+
end
1746
end
1847
end
1948

spec/controllers/email_callbacks_controller_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
describe "POST create" do
66
before { controller.stub(:respond_with) { controller.render text: '' } }
77

8-
it "tells the user to save the email callback" do
9-
controller.current_user.should_receive(:save_email_callback).with controller.email_callback
8+
it "tells the email callback to save" do
9+
controller.email_callback.should_receive(:save)
1010
post :create
1111
end
1212

@@ -32,8 +32,8 @@
3232
put :update, @params
3333
end
3434

35-
it "tells the current_user to save the email callback" do
36-
subject.current_user.should_receive(:save_email_callback).with @email_callback
35+
it "tells the email callback to save" do
36+
subject.email_callback.should_receive(:save)
3737
put :update, @params
3838
end
3939

spec/controllers/locations_controller/collection_actions_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
subject.stub(:location) { @location }
1212
end
1313

14-
it "tells the current_user to save the location" do
15-
subject.current_user.should_receive(:save_location).with @location
14+
it "tells the location to save and schedule a ping" do
15+
subject.location.should_receive :save_and_schedule_ping!
1616
post :create, @params
1717
end
1818

spec/controllers/locations_controller/member_actions_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
put :update, @params
1818
end
1919

20-
it "tells the current_user to save the location" do
21-
subject.current_user.should_receive(:save_location).with @location
20+
it "tells the location to save and schedule a ping" do
21+
subject.location.should_receive(:save_and_schedule_ping!)
2222
put :update, @params
2323
end
2424

spec/lib/pinger/user_spec.rb

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)