eventifier 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b2058a8b8853d745b422702127a30d6f813782f
4
- data.tar.gz: 15cc3e4c382f87e2fabb2e39c9491564125de1c1
3
+ metadata.gz: aaf9b70e8194f8a8d0b9bbb3c1f47a66ce567924
4
+ data.tar.gz: b5cfd42aac01fc16b8c3c6f1958c3f7000ccb61e
5
5
  SHA512:
6
- metadata.gz: 1c97b31eafca299de510fac186d067513d7172110217bc989b9e65fc44af6a3907cc056f39a4bda8f6b8f3ec70ec076bb11d19d809a5e1d5659e1ef78ec52054
7
- data.tar.gz: 09fe86cdb9b773bd3bbeeec95a575a20ec99b957d534e44474c2188b87a03c0fc491ee2e7cbe070bd7b7b451fd669ba93fc8b861fb072979ad7ec4e447e944be
6
+ metadata.gz: f33025942a2d0648a150905772630b8f5ffdf322529f3d03f4122c1d1799a6fcb159e3cedd83d9022dff49e92383db461647a33ca9719500572b22fb5781d56e
7
+ data.tar.gz: 2027a96019a98283036f41efa293c77140e1144c30c8bb41b05046e5786c851df26221c9fa0b98825ca16fba8bc6c4f8520cc17fff702adc8512b6620fba55f6
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in eventifier.gemspec
4
4
  gemspec
5
+
6
+ gem 'haml_coffee_assets',
7
+ git: 'git://github.com/netzpirat/haml_coffee_assets.git',
8
+ branch: 'master',
9
+ ref: 'a3c2951eca'
@@ -138,6 +138,19 @@ h2. Requirements
138
138
 
139
139
  * ActiveRecord
140
140
 
141
+ h2. Turbolinks
142
+
143
+ Turbolinks removes the body of the page, which is where our dropdown notifications box sits. We'll need to re-render it and point it at the holding element when the page changes.
144
+
145
+ ```
146
+ $ ->
147
+ window.notifications = new NotificationDropdown el: $('.notifications'), pollTime: 60
148
+
149
+ $(document).on "page:change", ->
150
+ notifications.el = $('.notifications')
151
+ notifications.render()
152
+ ```
153
+
141
154
  h2. Testing
142
155
 
143
156
  Creating the database:
@@ -1,6 +1,6 @@
1
1
  #= require hamlcoffee
2
- #= require ./templates/dropdown
3
- #= require ./templates/settings
2
+ #= require eventifier/templates/dropdown
3
+ #= require eventifier/templates/settings
4
4
  # Usage
5
5
  # window.notifications = new NotificationDropdown el: $('.notifications'), limit: 5
6
6
 
@@ -19,14 +19,18 @@ class window.NotificationDropdown
19
19
 
20
20
  @render()
21
21
  @loadMore(limit: 14)
22
+ setTimeout =>
23
+ @el.trigger 'poll'
24
+ , @pollTime*1000
22
25
 
23
26
  render: =>
27
+ @unsetEvents()
28
+ @renderedNotifications = []
24
29
  @el.html(@template(@)).attr('tabindex', 0)
25
-
30
+ @renderNotifications()
26
31
  # @checkVisibility()
27
32
 
28
33
  @setEvents()
29
- @poll()
30
34
 
31
35
  checkVisibility: =>
32
36
  @el.addClass("notifications_active").find('#notification_dropdown').attr('opacity': 0)
@@ -57,6 +61,9 @@ class window.NotificationDropdown
57
61
 
58
62
  @
59
63
 
64
+ unsetEvents: =>
65
+ @el.off()
66
+
60
67
  pushUrl: (e)=>
61
68
  location = $(e.currentTarget).attr('href')
62
69
  location = $('<a />').attr(href: location).get(0).pathname if location.match /^https?\:\/\//
@@ -72,16 +79,16 @@ class window.NotificationDropdown
72
79
  unless $.inArray(notification.id, @renderedNotifications) >= 0
73
80
  if new Date(notification.created_at) > @lastReadAt
74
81
  if @lastInserted?
75
- @lastInserted.after @lastInserted = $("<li />")
82
+ @lastInserted.after( @lastInserted = $("<li />")
76
83
  .addClass('unread')
77
84
  .html(notification.html)
85
+ )
78
86
  else
79
87
  @el
80
88
  .find('ol')
81
- .prepend( @lastInserted = $("<li />")
89
+ .prepend(@lastInserted = $("<li />")
82
90
  .addClass('unread')
83
- .html(notification.html)
84
- )
91
+ .html(notification.html))
85
92
  else
86
93
  @el
87
94
  .find('ol')
@@ -105,7 +112,7 @@ class window.NotificationDropdown
105
112
  toggleSettings: (event)=>
106
113
  event.preventDefault() if event?
107
114
  $.ajax
108
- url: "/preferences"
115
+ url: "/eventifier/preferences"
109
116
  success: (data)=>
110
117
  @el.find("#settings_pane").html(@settingsTemplate(data))
111
118
  @defaultSettings() if @arrayFromObject($.makeArray(data)).default
@@ -124,7 +131,7 @@ class window.NotificationDropdown
124
131
  serializedSettings[@name] = @value
125
132
 
126
133
  $.ajax
127
- url: "/preferences"
134
+ url: "/eventifier/preferences"
128
135
  type: "PUT"
129
136
  data: preferences: serializedSettings
130
137
  success: (data)=> @el.toggleClass('show_settings')
@@ -140,7 +147,7 @@ class window.NotificationDropdown
140
147
 
141
148
  loadMore: (params = {})=>
142
149
  $.ajax
143
- url: "/notifications"
150
+ url: "/eventifier/notifications"
144
151
  dataType: 'json'
145
152
  data: params
146
153
  success: @addNotifications
@@ -189,7 +196,7 @@ class window.NotificationDropdown
189
196
  if @isAlerting()
190
197
  @lastReadAt = new Date()
191
198
  @setUnreadCount()
192
- $.post '/notifications/touch'
199
+ $.post '/eventifier/notifications/touch'
193
200
 
194
201
  poll: =>
195
202
  @loadMore(recent: true, since: @lastLookTime())
@@ -151,6 +151,7 @@
151
151
  display: block;
152
152
  overflow: visible;
153
153
  padding-left: 38px;
154
+ word-break: break-all;
154
155
  }
155
156
  img.avatar {
156
157
  float: left;
@@ -1,6 +1,6 @@
1
- json.last_read_at current_user.notifications_last_read_at.to_i*1000
2
- json.notifications @notifications do |notification|
1
+ json.last_read_at user.notifications_last_read_at.to_i*1000
2
+ json.notifications notifications do |notification|
3
3
  json.(notification, :id)
4
4
  json.created_at notification.created_at.to_i*1000
5
5
  json.html render_partial_view(notification, :dropdown)
6
- end
6
+ end
@@ -1,7 +1,3 @@
1
1
  Eventifier::Engine.routes.draw do
2
- resources :notifications, module: 'eventifier' do
3
- collection { post :touch }
4
- end
5
-
6
- resource :preferences, module: 'eventifier'
2
+ mount Eventifier::API.new => '/eventifier'
7
3
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "eventifier"
4
- s.version = '0.1.2'
4
+ s.version = '0.1.3'
5
5
  s.authors = ["Nathan Sampimon", "Peter Murray", "Pat Allan"]
6
6
  s.email = ["nathan@inspire9.com"]
7
7
  s.homepage = "http://github.com/inspire9/eventifier"
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_runtime_dependency 'rails', '~> 4.0.3'
19
+ s.add_runtime_dependency 'rails', '>= 4.0.3'
20
20
  s.add_runtime_dependency "bson_ext"
21
21
  s.add_runtime_dependency 'haml-rails', '~> 0.4'
22
22
  s.add_runtime_dependency 'haml_coffee_assets'
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'multi_json', '>= 1.7.4'
26
26
  s.add_runtime_dependency 'jbuilder', '>= 2.0.4'
27
27
  s.add_runtime_dependency 'rails-observers', '~> 0.1.2'
28
+ s.add_runtime_dependency 'sliver', '~> 0.0.3'
28
29
 
29
30
  s.add_development_dependency 'combustion', '~> 0.5.0'
30
31
  s.add_development_dependency 'fabrication', '~> 2.11.0'
@@ -18,6 +18,7 @@ require 'compass-rails'
18
18
  require 'haml-rails'
19
19
  require 'haml_coffee_assets'
20
20
  require 'jbuilder'
21
+ require 'sliver'
21
22
 
22
23
  module Eventifier
23
24
  mattr_accessor :mailer_sender
@@ -60,7 +61,7 @@ module Eventifier
60
61
  end
61
62
  end
62
63
 
63
-
64
+ require 'eventifier/api'
64
65
  require 'eventifier/delivery'
65
66
  require 'eventifier/event_tracking'
66
67
  require 'eventifier/event_builder'
@@ -0,0 +1,19 @@
1
+ class Eventifier::API < Sliver::API
2
+ def initialize
3
+ super do |api|
4
+ api.connect :get, '/notifications', Eventifier::API::GetNotifications
5
+ api.connect :post, '/notifications/touch',
6
+ Eventifier::API::TouchNotifications
7
+
8
+ api.connect :get, '/preferences', Eventifier::API::GetPreferences
9
+ api.connect :put, '/preferences', Eventifier::API::PutPreferences
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'eventifier/api/base'
15
+ require 'eventifier/api/view'
16
+ require 'eventifier/api/get_notifications'
17
+ require 'eventifier/api/touch_notifications'
18
+ require 'eventifier/api/get_preferences'
19
+ require 'eventifier/api/put_preferences'
@@ -0,0 +1,36 @@
1
+ class Eventifier::API::Base
2
+ include Sliver::Action
3
+
4
+ def skip?
5
+ return false if user
6
+
7
+ response.status = 403
8
+ response.body = ['Forbidden']
9
+
10
+ true
11
+ end
12
+
13
+ def call
14
+ response.status ||= 200
15
+ response.body ||= {}
16
+ response.headers['Content-Type'] ||= 'application/json'
17
+
18
+ if response.body.is_a?(String)
19
+ response.body = [response.body]
20
+ else
21
+ response.body = [JSON.generate(response.body)]
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def user
28
+ return nil unless warden && warden.authenticated?(:user)
29
+
30
+ warden.user(:user)
31
+ end
32
+
33
+ def warden
34
+ environment['warden']
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ class Eventifier::API::GetNotifications < Eventifier::API::Base
2
+ include Eventifier::API::View
3
+
4
+ def call
5
+ render 'eventifier/notifications/index',
6
+ notifications: notifications, user: user
7
+
8
+ super
9
+ end
10
+
11
+ private
12
+
13
+ delegate :params, to: :request
14
+
15
+ def notifications
16
+ scope = user.notifications.order("eventifier_notifications.created_at DESC").limit(per_page)
17
+ scope = scope.where("eventifier_notifications.created_at < ?", after) if params['after']
18
+ scope = scope.where("eventifier_notifications.created_at > ?", since) if params['since']
19
+ scope = scope.where(
20
+ "eventifier_notifications.created_at > ?", user.notifications_last_read_at
21
+ ) if params['recent']
22
+
23
+ scope
24
+ end
25
+
26
+ def after
27
+ Time.zone.at params['after'].to_i
28
+ end
29
+
30
+ def per_page
31
+ (params['limit'] || 5).to_i
32
+ end
33
+
34
+ def since
35
+ Time.zone.at params['since'].to_i
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ class Eventifier::API::GetPreferences < Eventifier::API::Base
2
+ def call
3
+ response.body = Eventifier::Preferences.new(user).to_hashes
4
+
5
+ super
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class Eventifier::API::PutPreferences < Eventifier::API::Base
2
+ def call
3
+ Eventifier::Preferences.new(user).update request.params['preferences'] || {}
4
+
5
+ response.body = {'status' => 'OK'}
6
+
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Eventifier::API::TouchNotifications < Eventifier::API::Base
2
+ def call
3
+ user.update_attribute :notifications_last_read_at, Time.zone.now
4
+
5
+ response.body = {'status' => 'OK'}
6
+
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Eventifier::API::View
2
+ private
3
+
4
+ def render(template, locals = {})
5
+ response.body = renderer.render template: template, locals: locals
6
+ end
7
+
8
+ def renderer
9
+ ApplicationController.view_context_class.new(
10
+ ApplicationController.view_paths
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe Eventifier::API do
4
+ include Rack::Test::Methods
5
+
6
+ let(:app) { Eventifier::API.new }
7
+ let(:user) { double 'User' }
8
+ let(:warden) { double 'Warden', authenticated?: true, user: user }
9
+
10
+ describe 'GET /notifications' do
11
+ let(:event) { double 'Event', eventable_type: 'User', eventable: double, user: User.create!(name: 'Pat'), verb: :create }
12
+ let(:notifications) { [double('Notification', id: 84, created_at: created_at, event: event)] }
13
+ let(:created_at) { 1.minute.ago }
14
+
15
+ before :each do
16
+ Rails.application.default_url_options = {host: 'eventifier.dev'}
17
+
18
+ allow(user).to receive(:notifications_last_read_at).and_return(1)
19
+ allow(notifications).to receive(:order).and_return(notifications)
20
+ allow(notifications).to receive(:limit).and_return(notifications)
21
+ end
22
+
23
+ it 'returns 403 if there is no authenticated user' do
24
+ allow(warden).to receive(:authenticated?).and_return(false)
25
+ allow(warden).to receive(:user).and_return(nil)
26
+
27
+ get '/notifications', {}, {'warden' => warden}
28
+
29
+ expect(last_response.status).to eq(403)
30
+ end
31
+
32
+ it 'returns notifications as JSON' do
33
+ allow(user).to receive(:notifications).and_return(notifications)
34
+
35
+ get '/notifications', {}, {'warden' => warden}
36
+
37
+ json = JSON.parse(last_response.body)
38
+ expect(json['last_read_at']).to eq(1000)
39
+ expect(json['notifications'].first['id']).to eq(84)
40
+ end
41
+ end
42
+
43
+ describe 'POST /notifications/touch' do
44
+ before :each do
45
+ allow(user).to receive(:update_attribute).and_return(true)
46
+ end
47
+
48
+ it "updates the current user's notifications last read at" do
49
+ expect(user).to receive(:update_attribute).
50
+ with(:notifications_last_read_at, anything)
51
+
52
+ post '/notifications/touch', {}, {'warden' => warden}
53
+ end
54
+
55
+ it "responds with JSON OK status" do
56
+ post '/notifications/touch', {}, {'warden' => warden}
57
+
58
+ expect(last_response.body).to eq ({'status' => 'OK'}.to_json)
59
+ end
60
+ end
61
+
62
+ describe 'GET /preferences' do
63
+ let(:preferences) { double :to_hashes => [{'foo' => 'bar'}] }
64
+
65
+ before :each do
66
+ allow(Eventifier::Preferences).to receive(:new).and_return(preferences)
67
+ end
68
+
69
+ it 'initializes the preferences with the logged in user' do
70
+ expect(Eventifier::Preferences).to receive(:new).with(user).
71
+ and_return(preferences)
72
+
73
+ get '/preferences', {}, {'warden' => warden}
74
+ end
75
+
76
+ it "returns the settings hashes" do
77
+ get '/preferences', {}, {'warden' => warden}
78
+
79
+ expect(last_response.body).to eq ([{'foo' => 'bar'}].to_json)
80
+ end
81
+ end
82
+
83
+ describe 'PUT /preferences' do
84
+ let(:preferences) { double update: true }
85
+
86
+ before :each do
87
+ allow(Eventifier::Preferences).to receive(:new).and_return(preferences)
88
+ end
89
+
90
+ it 'initializes the preferences with the logged in user' do
91
+ expect(Eventifier::Preferences).to receive(:new).with(user).
92
+ and_return(preferences)
93
+
94
+ put '/preferences', {preferences: {'foo' => ''}}, {'warden' => warden}
95
+ end
96
+
97
+ it 'saves the settings changes' do
98
+ expect(preferences).to receive(:update).with('foo' => '')
99
+
100
+ put '/preferences', {preferences: {'foo' => ''}}, {'warden' => warden}
101
+ end
102
+
103
+ it "renders a JSON OK status" do
104
+ put '/preferences', {preferences: {'foo' => ''}}, {'warden' => warden}
105
+
106
+ expect(last_response.body).to eq ({'status' => 'OK'}.to_json)
107
+ end
108
+ end
109
+ end
@@ -18,3 +18,5 @@ en:
18
18
  update:
19
19
  single: "{{user.name}} updated a {{object_type}}"
20
20
  multiple: "{{user.name}} made some changes to a {{object_type}}"
21
+ test:
22
+ placeholder: true
@@ -5,6 +5,8 @@ Bundler.setup :default, :development
5
5
  require 'fabrication'
6
6
  require 'combustion'
7
7
  require 'active_record'
8
+ require 'action_view'
9
+ require 'haml'
8
10
  require 'eventifier'
9
11
 
10
12
  Fabrication.configure do |config|
@@ -12,7 +14,8 @@ Fabrication.configure do |config|
12
14
  config.path_prefix = '.'
13
15
  end
14
16
 
15
- Combustion.initialize! :action_controller, :active_record, :action_mailer
17
+ Combustion.initialize! :action_controller, :action_view, :active_record,
18
+ :action_mailer
16
19
 
17
20
  require 'rspec/rails'
18
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sampimon
@@ -10,20 +10,20 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-09 00:00:00.000000000 Z
13
+ date: 2014-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: 4.0.3
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 4.0.3
29
29
  - !ruby/object:Gem::Dependency
@@ -138,6 +138,20 @@ dependencies:
138
138
  - - "~>"
139
139
  - !ruby/object:Gem::Version
140
140
  version: 0.1.2
141
+ - !ruby/object:Gem::Dependency
142
+ name: sliver
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: 0.0.3
148
+ type: :runtime
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: 0.0.3
141
155
  - !ruby/object:Gem::Dependency
142
156
  name: combustion
143
157
  requirement: !ruby/object:Gem::Requirement
@@ -213,9 +227,6 @@ files:
213
227
  - app/assets/javascripts/eventifier/templates/dropdown.hamlc
214
228
  - app/assets/javascripts/eventifier/templates/settings.hamlc
215
229
  - app/assets/stylesheets/eventifier/notifications.scss
216
- - app/controllers/eventifier/application_controller.rb
217
- - app/controllers/eventifier/notifications_controller.rb
218
- - app/controllers/eventifier/preferences_controller.rb
219
230
  - app/helpers/eventifier/notification_helper.rb
220
231
  - app/helpers/eventifier/path_helper.rb
221
232
  - app/mailers/eventifier/mailer.rb
@@ -238,6 +249,13 @@ files:
238
249
  - db/migrate/5_system_events.rb
239
250
  - eventifier.gemspec
240
251
  - lib/eventifier.rb
252
+ - lib/eventifier/api.rb
253
+ - lib/eventifier/api/base.rb
254
+ - lib/eventifier/api/get_notifications.rb
255
+ - lib/eventifier/api/get_preferences.rb
256
+ - lib/eventifier/api/put_preferences.rb
257
+ - lib/eventifier/api/touch_notifications.rb
258
+ - lib/eventifier/api/view.rb
241
259
  - lib/eventifier/delivery.rb
242
260
  - lib/eventifier/engine.rb
243
261
  - lib/eventifier/event_builder.rb
@@ -258,9 +276,8 @@ files:
258
276
  - lib/generators/eventifier/install/templates/event_tracking.rb
259
277
  - lib/generators/eventifier/install/templates/events.en.yml
260
278
  - lib/tasks/email.rake
261
- - spec/controllers/eventifier/notifications_controller_spec.rb
262
- - spec/controllers/eventifier/preferences_controller_spec.rb
263
279
  - spec/event_tracking_spec.rb
280
+ - spec/eventifier/api_spec.rb
264
281
  - spec/eventifier/delivery_spec.rb
265
282
  - spec/eventifier/event_translator_spec.rb
266
283
  - spec/eventifier/notification_translator_spec.rb
@@ -321,9 +338,8 @@ signing_key:
321
338
  specification_version: 4
322
339
  summary: Event tracking and notifying for active record models
323
340
  test_files:
324
- - spec/controllers/eventifier/notifications_controller_spec.rb
325
- - spec/controllers/eventifier/preferences_controller_spec.rb
326
341
  - spec/event_tracking_spec.rb
342
+ - spec/eventifier/api_spec.rb
327
343
  - spec/eventifier/delivery_spec.rb
328
344
  - spec/eventifier/event_translator_spec.rb
329
345
  - spec/eventifier/notification_translator_spec.rb
@@ -1,4 +0,0 @@
1
- class Eventifier::ApplicationController < ApplicationController
2
- before_filter :authenticate_user!
3
- layout false
4
- end
@@ -1,36 +0,0 @@
1
- class Eventifier::NotificationsController < Eventifier::ApplicationController
2
- def index
3
- @notifications = notifications
4
- end
5
-
6
- def touch
7
- current_user.update_attribute :notifications_last_read_at, Time.zone.now
8
-
9
- render :json => {'status' => 'OK'}
10
- end
11
-
12
- private
13
-
14
- def notifications
15
- scope = current_user.notifications.order("eventifier_notifications.created_at DESC").limit(per_page)
16
- scope = scope.where("eventifier_notifications.created_at < ?", after) if params[:after]
17
- scope = scope.where("eventifier_notifications.created_at > ?", since) if params[:since]
18
- scope = scope.where(
19
- "eventifier_notifications.created_at > ?", current_user.notifications_last_read_at
20
- ) if params[:recent]
21
-
22
- scope
23
- end
24
-
25
- def after
26
- Time.zone.at params[:after].to_i
27
- end
28
-
29
- def per_page
30
- (params[:limit] || 5).to_i
31
- end
32
-
33
- def since
34
- Time.zone.at params[:since].to_i
35
- end
36
- end
@@ -1,17 +0,0 @@
1
- class Eventifier::PreferencesController < Eventifier::ApplicationController
2
- def show
3
- render :json => preferences.to_hashes
4
- end
5
-
6
- def update
7
- preferences.update params[:preferences] || {}
8
-
9
- render :json => {'status' => 'OK'}
10
- end
11
-
12
- private
13
-
14
- def preferences
15
- Eventifier::Preferences.new(current_user)
16
- end
17
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eventifier::NotificationsController do
4
- routes { Eventifier::Engine.routes }
5
-
6
- describe '#touch' do
7
- let(:user) { double 'User', :update_attribute => true }
8
-
9
- before :each do
10
- sign_in user
11
- end
12
-
13
- it "updates the current user's notifications last read at" do
14
- user.should_receive(:update_attribute).
15
- with(:notifications_last_read_at, anything)
16
-
17
- post :touch
18
- end
19
-
20
- it "responds with JSON OK status" do
21
- post :touch
22
-
23
- expect(response.body).to eq ({'status' => 'OK'}.to_json)
24
- end
25
- end
26
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eventifier::PreferencesController do
4
- routes { Eventifier::Engine.routes }
5
- let(:user) { double 'User' }
6
-
7
- before :each do
8
- sign_in user
9
-
10
- Eventifier::Preferences.stub :new => preferences
11
- end
12
-
13
- describe '#show' do
14
- let(:preferences) { double :to_hashes => [{'foo' => 'bar'}] }
15
-
16
- it "returns the settings hashes" do
17
- get :show
18
-
19
- expect(response.body).to eq ([{'foo' => 'bar'}].to_json)
20
- end
21
- end
22
-
23
- describe '#update' do
24
- let(:preferences) { double update: true }
25
-
26
- it 'saves the settings changes' do
27
- preferences.should_receive(:update).with('foo' => '')
28
-
29
- put :update, :preferences => {'foo' => ''}
30
- end
31
-
32
- it "renders a JSON OK status" do
33
- put :update, :preferences => {'foo' => ''}
34
-
35
- expect(response.body).to eq ({'status' => 'OK'}.to_json)
36
- end
37
- end
38
- end