filter blanks of slug when create a team

This commit is contained in:
2012-12-06 14:12:21 +08:00
parent 1fd6d145b4
commit ec6b5b4bb2
4 changed files with 20 additions and 3 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ class AntechamberController < ApplicationController
with_team do |team|
message = Message.create team: team, person: current_person, content: params[:content]
Pusher.trigger(team.name, 'new_message',{content:render_to_string( partial: 'shared/one_message', locals: {message: message})})
Pusher.trigger(team.slug, 'new_message',{content:render_to_string( partial: 'shared/one_message', locals: {message: message})})
render text:'ok'
end
+7
View File
@@ -4,6 +4,7 @@ class Team < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :slug
validates_uniqueness_of :slug
validate :format_slug ,:on => :create
has_many :memberships
has_many :people, through: :memberships
@@ -26,4 +27,10 @@ class Team < ActiveRecord::Base
def add_to (organisation)
organisations << organisation if organisation
end
def format_slug
slug.gsub!(/ /, "_") if slug
end
end
+2 -2
View File
@@ -8,8 +8,8 @@
h1 = @team.name
form.form-inline action="/antechamber/#{@team.slug}"
input type="hidden" id="pusher_key" value="#{ENV['PUSHER_KEY']}"
input type="hidden" id="team_name" value="#{@team.name}"
p #{text_area_tag :content, nil, placeholder: 'Enter Message', rows: 4,class:'message-body'}
input type="hidden" id="team_name" value="#{@team.slug}"
p #{text_area_tag :content, nil, placeholder: 'Enter Message', rows: 4 ,class:'message-body',style:"width:30%"}
a.btn.submit-mess Send
div.message-list
+10
View File
@@ -19,4 +19,14 @@ describe Team do
end
describe 'create team' do
it 'ensure when create a team,if team"s slug has blanks, it will be format to url string "' do
@person = Person.create_for_email 'test@thoughworks.com'
@team = @person.teams.create(name: 'LSP', slug: 'l s p')
@team.slug.should == 'l_s_p'
end
end
end