diff --git a/config/application.rb b/config/application.rb
index 79ba226..e9890ec 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -30,7 +30,7 @@ class Application < Rails::Application
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# JavaScript files you want as :defaults (application.js is always included).
- config.action_view.javascript_expansions[:defaults] = %w(jquery rails underscore json2 backbone jquery.cookie)
+ config.action_view.javascript_expansions[:defaults] = %w(jquery rails underscore json2 backbone jquery.cookie jquery.gritter.min)
config.action_view.javascript_expansions[:jquery_ui] = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.js"
config.action_view.javascript_expansions[:google] = "https://www.google.com/jsapi"
diff --git a/config/routes.rb b/config/routes.rb
index cfc29b9..166617b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,5 @@
Padelotron::Application.routes.draw do
+
match 'players/:id/graph_code' => 'graph#graph_code', :as => :graph_code
match 'players/:id/graph_games_played' => 'graph#graph_games_played', :as => :graph_games_played
@@ -43,8 +44,11 @@
get "sign_in", :to => "devise/sessions#new"
get "sign_out", :to => "devise/sessions#destroy"
end
- resources :players
-
+ resources :players do
+
+ end
+ resources :notifications
+
devise_for :customers, :controllers => { :registrations => "customers",
:confirmation => "customers/confirmations"}
devise_scope :customers do
diff --git a/db/migrate/20110902180233_create_notification_types.rb b/db/migrate/20110902180233_create_notification_types.rb
new file mode 100644
index 0000000..97c894f
--- /dev/null
+++ b/db/migrate/20110902180233_create_notification_types.rb
@@ -0,0 +1,13 @@
+class CreateNotificationTypes < ActiveRecord::Migration
+ def self.up
+ create_table :notification_types do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :notification_types
+ end
+end
diff --git a/db/migrate/20110902180309_create_notifications.rb b/db/migrate/20110902180309_create_notifications.rb
new file mode 100644
index 0000000..0ffe456
--- /dev/null
+++ b/db/migrate/20110902180309_create_notifications.rb
@@ -0,0 +1,16 @@
+class CreateNotifications < ActiveRecord::Migration
+ def self.up
+ create_table :notifications do |t|
+ t.references :player
+ t.references :notification_type
+ t.text :params
+ t.boolean :read, :default => false
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :notifications
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index b788ebb..5583197 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110902144146) do
+ActiveRecord::Schema.define(:version => 20110902180309) do
create_table "achievement_types", :force => true do |t|
t.string "name"
@@ -86,6 +86,21 @@
t.integer "playground_id"
end
+ create_table "notification_types", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "notifications", :force => true do |t|
+ t.integer "player_id"
+ t.integer "notification_type_id"
+ t.text "params"
+ t.boolean "read", :default => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "places", :force => true do |t|
t.string "name"
t.float "latitude"
diff --git a/public/images/gritter-long.png b/public/images/gritter-long.png
new file mode 100755
index 0000000..578b891
Binary files /dev/null and b/public/images/gritter-long.png differ
diff --git a/public/images/gritter.png b/public/images/gritter.png
new file mode 100755
index 0000000..0ca3bc0
Binary files /dev/null and b/public/images/gritter.png differ
diff --git a/public/images/ie-spacer.gif b/public/images/ie-spacer.gif
new file mode 100755
index 0000000..5bfd67a
Binary files /dev/null and b/public/images/ie-spacer.gif differ
diff --git a/public/images/trees.jpg b/public/images/trees.jpg
new file mode 100755
index 0000000..7caf603
Binary files /dev/null and b/public/images/trees.jpg differ
diff --git a/public/javascripts/jquery.gritter.min.js b/public/javascripts/jquery.gritter.min.js
new file mode 100755
index 0000000..9ca8edd
--- /dev/null
+++ b/public/javascripts/jquery.gritter.min.js
@@ -0,0 +1,11 @@
+/*
+ * Gritter for jQuery
+ * http://www.boedesign.com/
+ *
+ * Copyright (c) 2011 Jordan Boesch
+ * Dual licensed under the MIT and GPL licenses.
+ *
+ * Date: July 9, 2011
+ * Version: 1.7.1
+ */
+(function(b){b.gritter={};b.gritter.options={position:"",fade_in_speed:"medium",fade_out_speed:1000,time:6000};b.gritter.add=function(f){try{return a.add(f||{})}catch(d){var c="Gritter Error: "+d;(typeof(console)!="undefined"&&console.error)?console.error(c,f):alert(c)}};b.gritter.remove=function(d,c){a.removeSpecific(d,c||{})};b.gritter.removeAll=function(c){a.stop(c||{})};var a={position:"",fade_in_speed:"",fade_out_speed:"",time:"",_custom_timer:0,_item_count:0,_is_setup:0,_tpl_close:'',_tpl_item:'
[[close]][[image]]
[[username]]
[[text]]
',_tpl_wrap:'',add:function(g){if(!g.title||!g.text){throw'You need to fill out the first 2 params: "title" and "text"'}if(!this._is_setup){this._runSetup()}var i=g.title,n=g.text,e=g.image||"",l=g.sticky||false,m=g.class_name||"",k=b.gritter.options.position,d=g.time||"";this._verifyWrapper();this._item_count++;var f=this._item_count,j=this._tpl_item;b(["before_open","after_open","before_close","after_close"]).each(function(p,q){a["_"+q+"_"+f]=(b.isFunction(g[q]))?g[q]:function(){}});this._custom_timer=0;if(d){this._custom_timer=d}var c=(e!="")?'':"",h=(e!="")?"gritter-with-image":"gritter-without-image";j=this._str_replace(["[[username]]","[[text]]","[[close]]","[[image]]","[[number]]","[[class_name]]","[[item_class]]"],[i,n,this._tpl_close,c,this._item_count,h,m],j);this["_before_open_"+f]();b("#gritter-notice-wrapper").addClass(k).append(j);var o=b("#gritter-item-"+this._item_count);o.fadeIn(this.fade_in_speed,function(){a["_after_open_"+f](b(this))});if(!l){this._setFadeTimer(o,f)}b(o).bind("mouseenter mouseleave",function(p){if(p.type=="mouseenter"){if(!l){a._restoreItemIfFading(b(this),f)}}else{if(!l){a._setFadeTimer(b(this),f)}}a._hoverState(b(this),p.type)});return f},_countRemoveWrapper:function(c,d,f){d.remove();this["_after_close_"+c](d,f);if(b(".gritter-item-wrapper").length==0){b("#gritter-notice-wrapper").remove()}},_fade:function(f,c,h,d){var h=h||{},g=(typeof(h.fade)!="undefined")?h.fade:true;fade_out_speed=h.speed||this.fade_out_speed,manual_close=d;this["_before_close_"+c](f,manual_close);if(d){f.unbind("mouseenter mouseleave")}if(g){f.animate({opacity:0},fade_out_speed,function(){f.animate({height:0},300,function(){a._countRemoveWrapper(c,f,manual_close)})})}else{this._countRemoveWrapper(c,f)}},_hoverState:function(d,c){if(c=="mouseenter"){d.addClass("hover");d.find(".gritter-close").show();d.find(".gritter-close").click(function(){var e=d.attr("id").split("-")[2];a.removeSpecific(e,{},d,true)})}else{d.removeClass("hover");d.find(".gritter-close").hide()}},removeSpecific:function(c,g,f,d){if(!f){var f=b("#gritter-item-"+c)}this._fade(f,c,g||{},d)},_restoreItemIfFading:function(d,c){clearTimeout(this["_int_id_"+c]);d.stop().css({opacity:""})},_runSetup:function(){for(opt in b.gritter.options){this[opt]=b.gritter.options[opt]}this._is_setup=1},_setFadeTimer:function(f,d){var c=(this._custom_timer)?this._custom_timer:this.time;this["_int_id_"+d]=setTimeout(function(){a._fade(f,d)},c)},stop:function(e){var c=(b.isFunction(e.before_close))?e.before_close:function(){};var f=(b.isFunction(e.after_close))?e.after_close:function(){};var d=b("#gritter-notice-wrapper");c(d);d.fadeOut(function(){b(this).remove();f()})},_str_replace:function(v,e,o,n){var k=0,h=0,t="",m="",g=0,q=0,l=[].concat(v),c=[].concat(e),u=o,d=c instanceof Array,p=u instanceof Array;u=[].concat(u);if(n){this.window[n]=0}for(k=0,g=u.length;k 0){
+ $.when( $.ajax("/notifications.json")).then(function(data, status){
+ $("#notifications_button").addClass("with_notifications");
+ this.set({"notifications": data});
+ var urgentNotifications = _(data).find(function(notif){
+ return notif.params.urgent == true;
+ });
+ for (var i=0; i notification.id.to_s
+ assigns(:notification).should eq(notification)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new notification as @notification" do
+ get :new
+ assigns(:notification).should be_a_new(Notification)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested notification as @notification" do
+ notification = Notification.create! valid_attributes
+ get :edit, :id => notification.id.to_s
+ assigns(:notification).should eq(notification)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Notification" do
+ expect {
+ post :create, :notification => valid_attributes
+ }.to change(Notification, :count).by(1)
+ end
+
+ it "assigns a newly created notification as @notification" do
+ post :create, :notification => valid_attributes
+ assigns(:notification).should be_a(Notification)
+ assigns(:notification).should be_persisted
+ end
+
+ it "redirects to the created notification" do
+ post :create, :notification => valid_attributes
+ response.should redirect_to(Notification.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved notification as @notification" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Notification.any_instance.stub(:save).and_return(false)
+ post :create, :notification => {}
+ assigns(:notification).should be_a_new(Notification)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Notification.any_instance.stub(:save).and_return(false)
+ post :create, :notification => {}
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested notification" do
+ notification = Notification.create! valid_attributes
+ # Assuming there are no other notifications in the database, this
+ # specifies that the Notification created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ Notification.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, :id => notification.id, :notification => {'these' => 'params'}
+ end
+
+ it "assigns the requested notification as @notification" do
+ notification = Notification.create! valid_attributes
+ put :update, :id => notification.id, :notification => valid_attributes
+ assigns(:notification).should eq(notification)
+ end
+
+ it "redirects to the notification" do
+ notification = Notification.create! valid_attributes
+ put :update, :id => notification.id, :notification => valid_attributes
+ response.should redirect_to(notification)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the notification as @notification" do
+ notification = Notification.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Notification.any_instance.stub(:save).and_return(false)
+ put :update, :id => notification.id.to_s, :notification => {}
+ assigns(:notification).should eq(notification)
+ end
+
+ it "re-renders the 'edit' template" do
+ notification = Notification.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Notification.any_instance.stub(:save).and_return(false)
+ put :update, :id => notification.id.to_s, :notification => {}
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested notification" do
+ notification = Notification.create! valid_attributes
+ expect {
+ delete :destroy, :id => notification.id.to_s
+ }.to change(Notification, :count).by(-1)
+ end
+
+ it "redirects to the notifications list" do
+ notification = Notification.create! valid_attributes
+ delete :destroy, :id => notification.id.to_s
+ response.should redirect_to(notifications_url)
+ end
+ end
+
+end
diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb
new file mode 100644
index 0000000..f97959e
--- /dev/null
+++ b/spec/helpers/notifications_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the NotificationsHelper. For example:
+#
+# describe NotificationsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe NotificationsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb
new file mode 100644
index 0000000..2fc117a
--- /dev/null
+++ b/spec/models/notification_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Notification do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/models/notification_type_spec.rb b/spec/models/notification_type_spec.rb
new file mode 100644
index 0000000..31ae8c4
--- /dev/null
+++ b/spec/models/notification_type_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe NotificationType do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/requests/notifications_spec.rb b/spec/requests/notifications_spec.rb
new file mode 100644
index 0000000..07db7c0
--- /dev/null
+++ b/spec/requests/notifications_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Notifications" do
+ describe "GET /notifications" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get notifications_path
+ response.status.should be(200)
+ end
+ end
+end
diff --git a/spec/routing/notifications_routing_spec.rb b/spec/routing/notifications_routing_spec.rb
new file mode 100644
index 0000000..421a443
--- /dev/null
+++ b/spec/routing/notifications_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe NotificationsController do
+ describe "routing" do
+
+ it "routes to #index" do
+ get("/notifications").should route_to("notifications#index")
+ end
+
+ it "routes to #new" do
+ get("/notifications/new").should route_to("notifications#new")
+ end
+
+ it "routes to #show" do
+ get("/notifications/1").should route_to("notifications#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ get("/notifications/1/edit").should route_to("notifications#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ post("/notifications").should route_to("notifications#create")
+ end
+
+ it "routes to #update" do
+ put("/notifications/1").should route_to("notifications#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ delete("/notifications/1").should route_to("notifications#destroy", :id => "1")
+ end
+
+ end
+end
diff --git a/spec/views/notifications/edit.html.erb_spec.rb b/spec/views/notifications/edit.html.erb_spec.rb
new file mode 100644
index 0000000..9903d7b
--- /dev/null
+++ b/spec/views/notifications/edit.html.erb_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe "notifications/edit.html.erb" do
+ before(:each) do
+ @notification = assign(:notification, stub_model(Notification,
+ :player => "",
+ :notification_type => nil,
+ :params => "MyText",
+ :read => false
+ ))
+ end
+
+ it "renders the edit notification form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => notifications_path(@notification), :method => "post" do
+ assert_select "input#notification_player", :name => "notification[player]"
+ assert_select "input#notification_notification_type", :name => "notification[notification_type]"
+ assert_select "textarea#notification_params", :name => "notification[params]"
+ assert_select "input#notification_read", :name => "notification[read]"
+ end
+ end
+end
diff --git a/spec/views/notifications/index.html.erb_spec.rb b/spec/views/notifications/index.html.erb_spec.rb
new file mode 100644
index 0000000..a432dd4
--- /dev/null
+++ b/spec/views/notifications/index.html.erb_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe "notifications/index.html.erb" do
+ before(:each) do
+ assign(:notifications, [
+ stub_model(Notification,
+ :player => "",
+ :notification_type => nil,
+ :params => "MyText",
+ :read => false
+ ),
+ stub_model(Notification,
+ :player => "",
+ :notification_type => nil,
+ :params => "MyText",
+ :read => false
+ )
+ ])
+ end
+
+ it "renders a list of notifications" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => "".to_s, :count => 2
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => nil.to_s, :count => 2
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => "MyText".to_s, :count => 2
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => false.to_s, :count => 2
+ end
+end
diff --git a/spec/views/notifications/new.html.erb_spec.rb b/spec/views/notifications/new.html.erb_spec.rb
new file mode 100644
index 0000000..e521cc6
--- /dev/null
+++ b/spec/views/notifications/new.html.erb_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe "notifications/new.html.erb" do
+ before(:each) do
+ assign(:notification, stub_model(Notification,
+ :player => "",
+ :notification_type => nil,
+ :params => "MyText",
+ :read => false
+ ).as_new_record)
+ end
+
+ it "renders new notification form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => notifications_path, :method => "post" do
+ assert_select "input#notification_player", :name => "notification[player]"
+ assert_select "input#notification_notification_type", :name => "notification[notification_type]"
+ assert_select "textarea#notification_params", :name => "notification[params]"
+ assert_select "input#notification_read", :name => "notification[read]"
+ end
+ end
+end
diff --git a/spec/views/notifications/show.html.erb_spec.rb b/spec/views/notifications/show.html.erb_spec.rb
new file mode 100644
index 0000000..7cbea25
--- /dev/null
+++ b/spec/views/notifications/show.html.erb_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe "notifications/show.html.erb" do
+ before(:each) do
+ @notification = assign(:notification, stub_model(Notification,
+ :player => "",
+ :notification_type => nil,
+ :params => "MyText",
+ :read => false
+ ))
+ end
+
+ it "renders attributes in
" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(//)
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(//)
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(/MyText/)
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(/false/)
+ end
+end