diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb new file mode 100644 index 0000000..7f4e101 --- /dev/null +++ b/app/controllers/notifications_controller.rb @@ -0,0 +1,60 @@ +class NotificationsController < ApplicationController + before_filter :authenticate_player!, :load_player + # GET /notifications + # GET /notifications.xml + def index + @notifications = @player.notifications.unread.all + + respond_to do |format| + format.json { render :json => @notifications } + end + end + + # GET /notifications/1 + # GET /notifications/1.xml + def show + @notification = @player.notifications.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @notification } + end + end + + + # PUT /notifications/1 + # PUT /notifications/1.xml + def update + @notification = @player.notifications.find(params[:id]) + + respond_to do |format| + if @notification.update_attributes(params[:notification]) + format.html { redirect_to(@notification, :notice => 'Notification was successfully updated.') } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @notification.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /notifications/1 + # DELETE /notifications/1.xml + def destroy + @notification = @player.notifications.find(params[:id]) + @notification.destroy + + respond_to do |format| + format.html { redirect_to(notifications_url) } + format.xml { head :ok } + end + end + + private + + def load_player + @player = current_player + end + + +end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb new file mode 100644 index 0000000..7342393 --- /dev/null +++ b/app/helpers/notifications_helper.rb @@ -0,0 +1,2 @@ +module NotificationsHelper +end diff --git a/app/models/confirmable.rb b/app/models/confirmable.rb index 2de23b1..7e34dc8 100644 --- a/app/models/confirmable.rb +++ b/app/models/confirmable.rb @@ -6,7 +6,8 @@ module Confirmable after_create :set_initial_status, :create_confirmations_if_needed, - :deliver_ask_email + :deliver_ask_email, + :create_ask_notifications default_scope where(:status => "confirmed") @@ -47,6 +48,14 @@ def create_confirmations_if_needed end end + def create_ask_notifications + confirmating_player_groups.each do |notificating_group| + notificating_group.players.each do |player| + player.notifications.create NotificationType.NEW_TEAM + end + end + end + def mailer "#{self.class}Mailer".constantize end diff --git a/app/models/game.rb b/app/models/game.rb index 9ae9865..010ad31 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -116,7 +116,7 @@ def create_facebook_game_event(initiator_player,facebook_token) private def confirmating_player_groups - teams + self.team2 end def create_playground_request_if_needed diff --git a/app/models/notification.rb b/app/models/notification.rb new file mode 100644 index 0000000..3a9636b --- /dev/null +++ b/app/models/notification.rb @@ -0,0 +1,19 @@ +class Notification < ActiveRecord::Base + belongs_to :notification_type + belongs_to :player + + serialize :params + + default_scope includes(:notification_type) + + scope :unread, where(:read => false) + + def type + notification_type.name + end + + def as_json(options = {}) + super(:only => [:id, :created_at, :params, :read], + :methods => [:type]) + end +end diff --git a/app/models/notification_type.rb b/app/models/notification_type.rb new file mode 100644 index 0000000..ee6dba1 --- /dev/null +++ b/app/models/notification_type.rb @@ -0,0 +1,59 @@ +class NotificationType < ActiveRecord::Base + belongs_to :notification + + scope :named, lambda {|name| where('name = ?', name)} + + + def self.create_all_notification_types + NotificationType.create(:name => "new_player") + NotificationType.create(:name => "new_team") + NotificationType.create(:name => "team_accepted") + NotificationType.create(:name => "new_game") + NotificationType.create(:name => "game_accepted") + NotificationType.create(:name => "new_result") + NotificationType.create(:name => "result_accepted") + end + create_all_notification_types if self.all.blank?; + + + def NotificationType.NEW_PLAYER + { + :notification_type_id => NotificationType.named("new_player").first.id, + :params => { + :title => "Welcome to Padelotron", + :message => "As your first actions, yo can create a new team, invite friends or check today's games in your area", + :urgent => true + } + } + end + + def NotificationType.NEW_TEAM + { + :notification_type_id => NotificationType.named("new_team").first.id, + :params => { + :title => "New Team Request", + :message => "You have received an offer to join a team"} + } + end + + def NotificationType.TEAM_ACCEPTED + { + :notification_type_id => NotificationType.named("team_accepted").first.id, + :params => { + :title => "Team Joined", + :message => "You have joined a new team" + } + } + end + + def NotificationType.NEW_GAME + { + :notification_type_id => NotificationType.named("new_game").first.id, + :params => { + :title => "Team Joined", + :message => "You have joined a new team" + } + } + end + +end diff --git a/app/models/player.rb b/app/models/player.rb index ac38bae..2ed1dea 100644 --- a/app/models/player.rb +++ b/app/models/player.rb @@ -3,13 +3,13 @@ class Player < ActiveRecord::Base validates :email, :presence => true, :uniqueness => true has_many :teams, :finder_sql => 'select * from teams t where t.player1_id = #{id} or t.player2_id = #{id}' - + has_many :notifications has_many :player_games, :class_name => "Game", :finder_sql => 'select * from games ' include Statable devise :database_authenticatable, :omniauthable, :rememberable - before_create :init_devise_password + before_create :init_devise_password,:create_welcome_notification before_create :geocode_with_gmaps before_update :geocode_with_gmaps @@ -79,4 +79,10 @@ def get_geocode_attribute_value(loc, att) def init_devise_password password = Devise.friendly_token[0,20] end + + def create_welcome_notifications + notification= NotificationType.NEW_PLAYER + notification[:params][:name] = self.name + @player.notifications.create notification + end end diff --git a/app/models/result.rb b/app/models/result.rb index 516de33..f2a600a 100644 --- a/app/models/result.rb +++ b/app/models/result.rb @@ -67,7 +67,7 @@ def rejection_ask_message private def confirmating_player_groups - game.teams + game.winner == team1 ? team2 : team1 end end diff --git a/app/views/notifications/_form.html.erb b/app/views/notifications/_form.html.erb new file mode 100644 index 0000000..c057348 --- /dev/null +++ b/app/views/notifications/_form.html.erb @@ -0,0 +1,33 @@ +<%= form_for(@notification) do |f| %> + <% if @notification.errors.any? %> +
+

<%= pluralize(@notification.errors.count, "error") %> prohibited this notification from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :player %>
+ <%= f.text_field :player %> +
+
+ <%= f.label :notification_type %>
+ <%= f.text_field :notification_type %> +
+
+ <%= f.label :params %>
+ <%= f.text_area :params %> +
+
+ <%= f.label :read %>
+ <%= f.check_box :read %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/notifications/edit.html.erb b/app/views/notifications/edit.html.erb new file mode 100644 index 0000000..92c805b --- /dev/null +++ b/app/views/notifications/edit.html.erb @@ -0,0 +1,6 @@ +

Editing notification

+ +<%= render 'form' %> + +<%= link_to 'Show', @notification %> | +<%= link_to 'Back', notifications_path %> diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb new file mode 100644 index 0000000..90f7665 --- /dev/null +++ b/app/views/notifications/index.html.erb @@ -0,0 +1,29 @@ +

Listing notifications

+ + + + + + + + + + + + +<% @notifications.each do |notification| %> + + + + + + + + + +<% end %> +
PlayerNotification typeParamsRead
<%= notification.player %><%= notification.notification_type %><%= notification.params %><%= notification.read %><%= link_to 'Show', notification %><%= link_to 'Edit', edit_notification_path(notification) %><%= link_to 'Destroy', notification, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New Notification', new_notification_path %> diff --git a/app/views/notifications/new.html.erb b/app/views/notifications/new.html.erb new file mode 100644 index 0000000..e6fb48d --- /dev/null +++ b/app/views/notifications/new.html.erb @@ -0,0 +1,5 @@ +

New notification

+ +<%= render 'form' %> + +<%= link_to 'Back', notifications_path %> diff --git a/app/views/notifications/show.html.erb b/app/views/notifications/show.html.erb new file mode 100644 index 0000000..9c5e4e9 --- /dev/null +++ b/app/views/notifications/show.html.erb @@ -0,0 +1,25 @@ +

<%= notice %>

+ +

+ Player: + <%= @notification.player %> +

+ +

+ Notification type: + <%= @notification.notification_type %> +

+ +

+ Params: + <%= @notification.params %> +

+ +

+ Read: + <%= @notification.read %> +

+ + +<%= link_to 'Edit', edit_notification_path(@notification) %> | +<%= link_to 'Back', notifications_path %> diff --git a/app/views/players/_player_session_panel.html.erb b/app/views/players/_player_session_panel.html.erb index c225676..ce4f90a 100644 --- a/app/views/players/_player_session_panel.html.erb +++ b/app/views/players/_player_session_panel.html.erb @@ -1,4 +1,6 @@
+
<%= player_photo(player) %>
@@ -17,7 +19,7 @@ <%= link_to "Profile", player_home_path %>
  • - <%= link_to "News", teams_path %> + <%= link_to "News", teams_path, :id=>"notifications_button" %>
  • 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:'',_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