Commit 7fc69c350440ca97c43cdfb46c379c5e94c931e6
1 parent
0e2ca7e6
Exists in
master
and in
1 other branch
Clean up whitespace. My editor strips whitespace before saving the file, so I'll…
… just commit this all at once.
I used the following command to do this: (on Ubuntu )
find . -not -path '.git' -iname '*.rb' -print0 | xargs -0 sed -i 's/[[:space:]]*$//'
Showing
22 changed files
with
148 additions
and
148 deletions
Show diff stats
app/controllers/application_controller.rb
| 1 | 1 | class ApplicationController < ActionController::Base |
| 2 | 2 | protect_from_forgery |
| 3 | - | |
| 3 | + | |
| 4 | 4 | before_filter :authenticate_user! |
| 5 | - | |
| 5 | + | |
| 6 | 6 | protected |
| 7 | - | |
| 7 | + | |
| 8 | 8 | def require_admin! |
| 9 | 9 | redirect_to(root_path) and return(false) unless user_signed_in? && current_user.admin? |
| 10 | 10 | end |
| 11 | - | |
| 11 | + | |
| 12 | 12 | end | ... | ... |
app/controllers/deploys_controller.rb
| 1 | 1 | class DeploysController < ApplicationController |
| 2 | 2 | |
| 3 | 3 | protect_from_forgery :except => :create |
| 4 | - | |
| 4 | + | |
| 5 | 5 | skip_before_filter :verify_authenticity_token, :only => :create |
| 6 | 6 | skip_before_filter :authenticate_user!, :only => :create |
| 7 | - | |
| 7 | + | |
| 8 | 8 | def create |
| 9 | 9 | @app = App.find_by_api_key!(params[:api_key]) |
| 10 | 10 | if params[:deploy] |
| ... | ... | @@ -29,12 +29,12 @@ class DeploysController < ApplicationController |
| 29 | 29 | render :xml => @deploy |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | - def index | |
| 33 | - # See AppsController#find_app for the reasoning behind this code. | |
| 32 | + def index | |
| 33 | + # See AppsController#find_app for the reasoning behind this code. | |
| 34 | 34 | app = App.find(params[:app_id]) |
| 35 | 35 | raise(Mongoid::Errors::DocumentNotFound.new(App,app.id)) unless current_user.admin? || current_user.watching?(app) |
| 36 | 36 | |
| 37 | 37 | @deploys = app.deploys.order_by(:created_at.desc).paginate(:page => params[:page], :per_page => 10) |
| 38 | 38 | end |
| 39 | - | |
| 39 | + | |
| 40 | 40 | end | ... | ... |
app/controllers/notices_controller.rb
| 1 | 1 | class NoticesController < ApplicationController |
| 2 | 2 | respond_to :xml |
| 3 | - | |
| 3 | + | |
| 4 | 4 | skip_before_filter :authenticate_user!, :only => :create |
| 5 | - | |
| 5 | + | |
| 6 | 6 | def create |
| 7 | 7 | # params[:data] if the notice came from a GET request, raw_post if it came via POST |
| 8 | 8 | @notice = Notice.from_xml(params[:data] || request.raw_post) |
| 9 | 9 | respond_with @notice |
| 10 | 10 | end |
| 11 | - | |
| 11 | + | |
| 12 | 12 | end | ... | ... |
app/controllers/users_controller.rb
| 1 | 1 | class UsersController < ApplicationController |
| 2 | 2 | respond_to :html |
| 3 | - | |
| 3 | + | |
| 4 | 4 | before_filter :require_admin!, :except => [:edit, :update] |
| 5 | 5 | before_filter :find_user, :only => [:show, :edit, :update, :destroy] |
| 6 | 6 | before_filter :require_user_edit_priviledges, :only => [:edit, :update] |
| 7 | - | |
| 7 | + | |
| 8 | 8 | def index |
| 9 | 9 | @users = User.all.paginate(:page => params[:page], :per_page => current_user.per_page) |
| 10 | 10 | end |
| 11 | - | |
| 11 | + | |
| 12 | 12 | def show |
| 13 | 13 | @user = User.find(params[:id]) |
| 14 | 14 | end |
| 15 | - | |
| 15 | + | |
| 16 | 16 | def new |
| 17 | 17 | @user = User.new |
| 18 | 18 | end |
| 19 | - | |
| 19 | + | |
| 20 | 20 | def edit |
| 21 | 21 | end |
| 22 | - | |
| 22 | + | |
| 23 | 23 | def create |
| 24 | 24 | @user = User.new(params[:user]) |
| 25 | - | |
| 25 | + | |
| 26 | 26 | # Set protected attributes |
| 27 | 27 | @user.admin = params[:user].try(:[], :admin) if current_user.admin? |
| 28 | - | |
| 28 | + | |
| 29 | 29 | if @user.save |
| 30 | 30 | flash[:success] = "#{@user.name} is now part of the team. Be sure to add them as a project watcher." |
| 31 | 31 | redirect_to user_path(@user) |
| ... | ... | @@ -33,17 +33,17 @@ class UsersController < ApplicationController |
| 33 | 33 | render :new |
| 34 | 34 | end |
| 35 | 35 | end |
| 36 | - | |
| 36 | + | |
| 37 | 37 | def update |
| 38 | 38 | # Devise Hack |
| 39 | 39 | if params[:user][:password].blank? && params[:user][:password_confirmation].blank? |
| 40 | 40 | params[:user].delete(:password) |
| 41 | 41 | params[:user].delete(:password_confirmation) |
| 42 | 42 | end |
| 43 | - | |
| 43 | + | |
| 44 | 44 | # Set protected attributes |
| 45 | 45 | @user.admin = params[:user][:admin] if current_user.admin? |
| 46 | - | |
| 46 | + | |
| 47 | 47 | if @user.update_attributes(params[:user]) |
| 48 | 48 | flash[:success] = "#{@user.name}'s information was successfully updated" |
| 49 | 49 | redirect_to user_path(@user) |
| ... | ... | @@ -51,16 +51,16 @@ class UsersController < ApplicationController |
| 51 | 51 | render :edit |
| 52 | 52 | end |
| 53 | 53 | end |
| 54 | - | |
| 54 | + | |
| 55 | 55 | def destroy |
| 56 | 56 | @user.destroy |
| 57 | - | |
| 57 | + | |
| 58 | 58 | flash[:success] = "That's sad. #{@user.name} is no longer part of your team." |
| 59 | 59 | redirect_to users_path |
| 60 | 60 | end |
| 61 | - | |
| 61 | + | |
| 62 | 62 | protected |
| 63 | - | |
| 63 | + | |
| 64 | 64 | def find_user |
| 65 | 65 | @user = User.find(params[:id]) |
| 66 | 66 | end |
| ... | ... | @@ -69,5 +69,5 @@ class UsersController < ApplicationController |
| 69 | 69 | can_edit = current_user == @user || current_user.admin? |
| 70 | 70 | redirect_to(root_path) and return(false) unless can_edit |
| 71 | 71 | end |
| 72 | - | |
| 72 | + | |
| 73 | 73 | end | ... | ... |
app/helpers/errs_helper.rb
| 1 | 1 | module ErrsHelper |
| 2 | - | |
| 2 | + | |
| 3 | 3 | def last_notice_at err |
| 4 | 4 | err.last_notice_at || err.created_at |
| 5 | 5 | end |
| ... | ... | @@ -7,12 +7,12 @@ module ErrsHelper |
| 7 | 7 | def err_confirm |
| 8 | 8 | Errbit::Config.confirm_resolve_err === false ? nil : 'Seriously?' |
| 9 | 9 | end |
| 10 | - | |
| 10 | + | |
| 11 | 11 | def link_to_github app, line, text=nil |
| 12 | 12 | file_name = line['file'].split('/').last |
| 13 | 13 | file_path = line['file'].gsub('[PROJECT_ROOT]', '') |
| 14 | 14 | line_number = line['number'] |
| 15 | 15 | link_to(text || file_name, "#{app.github_url_to_file(file_path)}#L#{line_number}", :target => '_blank') |
| 16 | 16 | end |
| 17 | - | |
| 17 | + | |
| 18 | 18 | end |
| 19 | 19 | \ No newline at end of file | ... | ... |
app/helpers/form_helper.rb
| 1 | 1 | module FormHelper |
| 2 | - | |
| 2 | + | |
| 3 | 3 | def errors_for(document) |
| 4 | 4 | return unless document.errors.any? |
| 5 | - | |
| 5 | + | |
| 6 | 6 | content_tag(:div, :class => 'error-messages') do |
| 7 | 7 | body = content_tag(:h2, 'Dang. The following errors are keeping this from being a success.') |
| 8 | 8 | body += content_tag(:ul) do |
| ... | ... | @@ -10,9 +10,9 @@ module FormHelper |
| 10 | 10 | end |
| 11 | 11 | end |
| 12 | 12 | end |
| 13 | - | |
| 13 | + | |
| 14 | 14 | def label_for_attr(builder, field) |
| 15 | 15 | (builder.object_name + field).gsub(/[\[\]]/,'_').squeeze('_') |
| 16 | 16 | end |
| 17 | - | |
| 17 | + | |
| 18 | 18 | end |
| 19 | 19 | \ No newline at end of file | ... | ... |
app/helpers/hash_helper.rb
| 1 | 1 | module HashHelper |
| 2 | - | |
| 2 | + | |
| 3 | 3 | def pretty_hash(hash, nesting = 0) |
| 4 | 4 | tab_size = 2 |
| 5 | 5 | nesting += 1 |
| 6 | - | |
| 6 | + | |
| 7 | 7 | pretty = "{" |
| 8 | 8 | sorted_keys = hash.keys.sort |
| 9 | 9 | sorted_keys.each do |key| |
| ... | ... | @@ -16,5 +16,5 @@ module HashHelper |
| 16 | 16 | nesting -= 1 |
| 17 | 17 | pretty += "\n#{' '*nesting*tab_size}}" |
| 18 | 18 | end |
| 19 | - | |
| 19 | + | |
| 20 | 20 | end |
| 21 | 21 | \ No newline at end of file | ... | ... |
app/helpers/navigation_helper.rb
| 1 | 1 | module NavigationHelper |
| 2 | - | |
| 2 | + | |
| 3 | 3 | # Returns ' active' if you are on a given controller |
| 4 | 4 | # - active_if_here(:users) => ' active' if users controller |
| 5 | 5 | # Or on one of a list of controllers |
| ... | ... | @@ -14,7 +14,7 @@ module NavigationHelper |
| 14 | 14 | def active_if_here(matches) |
| 15 | 15 | current_controller = controller.controller_name.to_sym |
| 16 | 16 | current_action = controller.action_name.to_sym |
| 17 | - | |
| 17 | + | |
| 18 | 18 | sections = case matches |
| 19 | 19 | when Hash |
| 20 | 20 | matches |
| ... | ... | @@ -25,7 +25,7 @@ module NavigationHelper |
| 25 | 25 | else |
| 26 | 26 | {matches => :all} |
| 27 | 27 | end |
| 28 | - | |
| 28 | + | |
| 29 | 29 | active = nil |
| 30 | 30 | sections.each do |controller, actions| |
| 31 | 31 | actions = ([] << actions) unless actions.kind_of?(Array) |
| ... | ... | @@ -33,5 +33,5 @@ module NavigationHelper |
| 33 | 33 | end |
| 34 | 34 | active |
| 35 | 35 | end |
| 36 | - | |
| 36 | + | |
| 37 | 37 | end |
| 38 | 38 | \ No newline at end of file | ... | ... |
app/models/deploy.rb
| 1 | 1 | class Deploy |
| 2 | 2 | include Mongoid::Document |
| 3 | 3 | include Mongoid::Timestamps |
| 4 | - | |
| 4 | + | |
| 5 | 5 | field :username |
| 6 | 6 | field :repository |
| 7 | 7 | field :environment |
| ... | ... | @@ -9,30 +9,30 @@ class Deploy |
| 9 | 9 | field :message |
| 10 | 10 | |
| 11 | 11 | index :created_at, Mongo::DESCENDING |
| 12 | - | |
| 12 | + | |
| 13 | 13 | embedded_in :app, :inverse_of => :deploys |
| 14 | - | |
| 14 | + | |
| 15 | 15 | after_create :deliver_notification, :if => :should_notify? |
| 16 | 16 | after_create :resolve_app_errs, :if => :should_resolve_app_errs? |
| 17 | - | |
| 17 | + | |
| 18 | 18 | validates_presence_of :username, :environment |
| 19 | - | |
| 19 | + | |
| 20 | 20 | def deliver_notification |
| 21 | 21 | Mailer.deploy_notification(self).deliver |
| 22 | 22 | end |
| 23 | - | |
| 23 | + | |
| 24 | 24 | def resolve_app_errs |
| 25 | 25 | app.errs.unresolved.in_env(environment).each {|err| err.resolve!} |
| 26 | 26 | end |
| 27 | - | |
| 27 | + | |
| 28 | 28 | protected |
| 29 | - | |
| 29 | + | |
| 30 | 30 | def should_notify? |
| 31 | 31 | app.notify_on_deploys? && app.watchers.any? |
| 32 | 32 | end |
| 33 | - | |
| 33 | + | |
| 34 | 34 | def should_resolve_app_errs? |
| 35 | 35 | app.resolve_errs_on_deploy? |
| 36 | 36 | end |
| 37 | - | |
| 37 | + | |
| 38 | 38 | end | ... | ... |
app/models/user.rb
| ... | ... | @@ -13,11 +13,11 @@ class User |
| 13 | 13 | |
| 14 | 14 | after_destroy :destroy_watchers |
| 15 | 15 | before_save :ensure_authentication_token |
| 16 | - | |
| 16 | + | |
| 17 | 17 | validates_presence_of :name |
| 18 | - | |
| 18 | + | |
| 19 | 19 | attr_protected :admin |
| 20 | - | |
| 20 | + | |
| 21 | 21 | # Mongoid doesn't seem to currently support |
| 22 | 22 | # referencing embedded documents |
| 23 | 23 | def watchers |
| ... | ... | @@ -27,20 +27,20 @@ class User |
| 27 | 27 | def per_page |
| 28 | 28 | self[:per_page] || PER_PAGE |
| 29 | 29 | end |
| 30 | - | |
| 30 | + | |
| 31 | 31 | def apps |
| 32 | 32 | # This is completely wasteful but became necessary |
| 33 | - # due to bugs in Mongoid | |
| 33 | + # due to bugs in Mongoid | |
| 34 | 34 | app_ids = watchers.map {|w| w.app.id} |
| 35 | 35 | App.any_in(:_id => app_ids) |
| 36 | 36 | end |
| 37 | - | |
| 37 | + | |
| 38 | 38 | def watching?(app) |
| 39 | 39 | apps.all.include?(app) |
| 40 | 40 | end |
| 41 | - | |
| 41 | + | |
| 42 | 42 | protected |
| 43 | - | |
| 43 | + | |
| 44 | 44 | def destroy_watchers |
| 45 | 45 | watchers.each(&:destroy) |
| 46 | 46 | end | ... | ... |
app/models/watcher.rb
| 1 | 1 | class Watcher |
| 2 | 2 | include Mongoid::Document |
| 3 | 3 | include Mongoid::Timestamps |
| 4 | - | |
| 4 | + | |
| 5 | 5 | field :email |
| 6 | - | |
| 6 | + | |
| 7 | 7 | embedded_in :app, :inverse_of => :watchers |
| 8 | 8 | referenced_in :user |
| 9 | - | |
| 9 | + | |
| 10 | 10 | validate :ensure_user_or_email |
| 11 | - | |
| 11 | + | |
| 12 | 12 | before_validation :clear_unused_watcher_type |
| 13 | - | |
| 13 | + | |
| 14 | 14 | attr_accessor :watcher_type |
| 15 | - | |
| 15 | + | |
| 16 | 16 | def watcher_type |
| 17 | 17 | @watcher_type ||= email.present? ? 'email' : 'user' |
| 18 | 18 | end |
| 19 | - | |
| 19 | + | |
| 20 | 20 | def label |
| 21 | 21 | user ? user.name : email |
| 22 | 22 | end |
| 23 | - | |
| 23 | + | |
| 24 | 24 | def address |
| 25 | 25 | user.try(:email) || email |
| 26 | 26 | end |
| 27 | - | |
| 27 | + | |
| 28 | 28 | protected |
| 29 | - | |
| 29 | + | |
| 30 | 30 | def ensure_user_or_email |
| 31 | 31 | errors.add(:base, "You must specify either a user or an email address") unless user.present? || email.present? |
| 32 | 32 | end |
| 33 | - | |
| 33 | + | |
| 34 | 34 | def clear_unused_watcher_type |
| 35 | 35 | case watcher_type |
| 36 | 36 | when 'user' |
| ... | ... | @@ -39,5 +39,5 @@ class Watcher |
| 39 | 39 | self.user = self.user_id = nil |
| 40 | 40 | end |
| 41 | 41 | end |
| 42 | - | |
| 42 | + | |
| 43 | 43 | end | ... | ... |
config/application.rb
| ... | ... | @@ -38,7 +38,7 @@ module Errbit |
| 38 | 38 | |
| 39 | 39 | # JavaScript files you want as :defaults (application.js is always included). |
| 40 | 40 | config.action_view.javascript_expansions[:defaults] = %w(jquery rails form) |
| 41 | - | |
| 41 | + | |
| 42 | 42 | # > rails generate - config |
| 43 | 43 | config.generators do |g| |
| 44 | 44 | g.orm :mongoid | ... | ... |
config/deploy.example.rb
| ... | ... | @@ -48,7 +48,7 @@ namespace :errbit do |
| 48 | 48 | run "if [ ! -f #{shared_configs}/config.yml ]; then cp #{latest_release}/config/config.example.yml #{shared_configs}/config.yml; fi" |
| 49 | 49 | run "if [ ! -f #{shared_configs}/mongoid.yml ]; then cp #{latest_release}/config/mongoid.example.yml #{shared_configs}/mongoid.yml; fi" |
| 50 | 50 | end |
| 51 | - | |
| 51 | + | |
| 52 | 52 | task :symlink_configs do |
| 53 | 53 | errbit.setup_configs |
| 54 | 54 | shared_configs = File.join(shared_path,'config') | ... | ... |
config/initializers/devise.rb
| ... | ... | @@ -51,10 +51,10 @@ Devise.setup do |config| |
| 51 | 51 | # ==> Configuration for :confirmable |
| 52 | 52 | # The time you want to give your user to confirm his account. During this time |
| 53 | 53 | # he will be able to access your application without confirming. Default is nil. |
| 54 | - # When confirm_within is zero, the user won't be able to sign in without confirming. | |
| 55 | - # You can use this to let your user access some features of your application | |
| 56 | - # without confirming the account, but blocking it after a certain period | |
| 57 | - # (ie 2 days). | |
| 54 | + # When confirm_within is zero, the user won't be able to sign in without confirming. | |
| 55 | + # You can use this to let your user access some features of your application | |
| 56 | + # without confirming the account, but blocking it after a certain period | |
| 57 | + # (ie 2 days). | |
| 58 | 58 | # config.confirm_within = 2.days |
| 59 | 59 | |
| 60 | 60 | # ==> Configuration for :rememberable |
| ... | ... | @@ -113,7 +113,7 @@ Devise.setup do |config| |
| 113 | 113 | # devise role declared in your routes. |
| 114 | 114 | # config.default_scope = :user |
| 115 | 115 | |
| 116 | - # Configure sign_out behavior. | |
| 116 | + # Configure sign_out behavior. | |
| 117 | 117 | # By default sign_out is scoped (i.e. /users/sign_out affects only :user scope). |
| 118 | 118 | # In case of sign_out_all_scopes set to true any logout action will sign out all active scopes. |
| 119 | 119 | # config.sign_out_all_scopes = false | ... | ... |
spec/controllers/deploys_controller_spec.rb
| ... | ... | @@ -2,7 +2,7 @@ require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe DeploysController do |
| 4 | 4 | render_views |
| 5 | - | |
| 5 | + | |
| 6 | 6 | context 'POST #create' do |
| 7 | 7 | before do |
| 8 | 8 | @params = { |
| ... | ... | @@ -14,12 +14,12 @@ describe DeploysController do |
| 14 | 14 | } |
| 15 | 15 | @app = Factory(:app_with_watcher, :api_key => 'APIKEY') |
| 16 | 16 | end |
| 17 | - | |
| 17 | + | |
| 18 | 18 | it 'finds the app via the api key' do |
| 19 | 19 | App.should_receive(:find_by_api_key!).with('APIKEY').and_return(@app) |
| 20 | 20 | post :create, :deploy => @params, :api_key => 'APIKEY' |
| 21 | 21 | end |
| 22 | - | |
| 22 | + | |
| 23 | 23 | it 'creates a deploy' do |
| 24 | 24 | App.stub(:find_by_api_key!).and_return(@app) |
| 25 | 25 | @app.deploys.should_receive(:create!). |
| ... | ... | @@ -33,14 +33,14 @@ describe DeploysController do |
| 33 | 33 | }).and_return(Factory(:deploy)) |
| 34 | 34 | post :create, :deploy => @params, :api_key => 'APIKEY' |
| 35 | 35 | end |
| 36 | - | |
| 36 | + | |
| 37 | 37 | it 'sends an email notification' do |
| 38 | 38 | post :create, :deploy => @params, :api_key => 'APIKEY' |
| 39 | 39 | email = ActionMailer::Base.deliveries.last |
| 40 | 40 | email.to.should include(@app.watchers.first.email) |
| 41 | 41 | email.subject.should == "[#{@app.name}] Deployed to production by john.doe" |
| 42 | 42 | end |
| 43 | - | |
| 43 | + | |
| 44 | 44 | end |
| 45 | 45 | |
| 46 | 46 | context "GET #index" do |
| ... | ... | @@ -59,5 +59,5 @@ describe DeploysController do |
| 59 | 59 | response.body.should match(@deploy.app.name) |
| 60 | 60 | end |
| 61 | 61 | end |
| 62 | - | |
| 62 | + | |
| 63 | 63 | end |
| 64 | 64 | \ No newline at end of file | ... | ... |
spec/controllers/notices_controller_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe NoticesController do |
| 4 | - | |
| 4 | + | |
| 5 | 5 | context 'notices API' do |
| 6 | 6 | before do |
| 7 | 7 | @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read |
| 8 | 8 | @app = Factory(:app_with_watcher) |
| 9 | 9 | App.stub(:find_by_api_key!).and_return(@app) |
| 10 | 10 | @notice = Notice.from_xml(@xml) |
| 11 | - | |
| 11 | + | |
| 12 | 12 | request.env['Content-type'] = 'text/xml' |
| 13 | 13 | request.env['Accept'] = 'text/xml, application/xml' |
| 14 | 14 | end |
| 15 | - | |
| 15 | + | |
| 16 | 16 | it "generates a notice from xml [POST]" do |
| 17 | 17 | Notice.should_receive(:from_xml).with(@xml).and_return(@notice) |
| 18 | 18 | request.should_receive(:raw_post).and_return(@xml) |
| 19 | 19 | post :create |
| 20 | 20 | end |
| 21 | - | |
| 21 | + | |
| 22 | 22 | it "generates a notice from xml [GET]" do |
| 23 | 23 | Notice.should_receive(:from_xml).with(@xml).and_return(@notice) |
| 24 | 24 | get :create, {:data => @xml} |
| 25 | 25 | end |
| 26 | - | |
| 26 | + | |
| 27 | 27 | it "sends a notification email" do |
| 28 | 28 | request.should_receive(:raw_post).and_return(@xml) |
| 29 | 29 | post :create |
| ... | ... | @@ -34,5 +34,5 @@ describe NoticesController do |
| 34 | 34 | email.subject.should include("[#{@notice.err.environment}]") |
| 35 | 35 | end |
| 36 | 36 | end |
| 37 | - | |
| 37 | + | |
| 38 | 38 | end | ... | ... |
spec/controllers/users_controller_spec.rb
| ... | ... | @@ -2,7 +2,7 @@ require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe UsersController do |
| 4 | 4 | render_views |
| 5 | - | |
| 5 | + | |
| 6 | 6 | it_requires_authentication |
| 7 | 7 | it_requires_admin_privileges :for => { |
| 8 | 8 | :index => :get, |
| ... | ... | @@ -11,19 +11,19 @@ describe UsersController do |
| 11 | 11 | :create => :post, |
| 12 | 12 | :destroy => :delete |
| 13 | 13 | } |
| 14 | - | |
| 14 | + | |
| 15 | 15 | context 'Signed in as a regular user' do |
| 16 | 16 | before do |
| 17 | 17 | sign_in @user = Factory(:user) |
| 18 | 18 | end |
| 19 | - | |
| 19 | + | |
| 20 | 20 | context "GET /users/:other_id/edit" do |
| 21 | 21 | it "redirects to the home page" do |
| 22 | 22 | get :edit, :id => Factory(:user).id |
| 23 | 23 | response.should redirect_to(root_path) |
| 24 | 24 | end |
| 25 | 25 | end |
| 26 | - | |
| 26 | + | |
| 27 | 27 | context "GET /users/:my_id/edit" do |
| 28 | 28 | it 'finds the user' do |
| 29 | 29 | get :edit, :id => @user.id |
| ... | ... | @@ -35,26 +35,26 @@ describe UsersController do |
| 35 | 35 | response.body.should match(/id="user_per_page"/) |
| 36 | 36 | end |
| 37 | 37 | end |
| 38 | - | |
| 38 | + | |
| 39 | 39 | context "PUT /users/:other_id" do |
| 40 | 40 | it "redirects to the home page" do |
| 41 | 41 | put :update, :id => Factory(:user).id |
| 42 | 42 | response.should redirect_to(root_path) |
| 43 | 43 | end |
| 44 | 44 | end |
| 45 | - | |
| 45 | + | |
| 46 | 46 | context "PUT /users/:my_id/id" do |
| 47 | - context "when the update is successful" do | |
| 47 | + context "when the update is successful" do | |
| 48 | 48 | it "sets a message to display" do |
| 49 | 49 | put :update, :id => @user.to_param, :user => {:name => 'Kermit'} |
| 50 | 50 | request.flash[:success].should include('updated') |
| 51 | 51 | end |
| 52 | - | |
| 52 | + | |
| 53 | 53 | it "redirects to the user's page" do |
| 54 | 54 | put :update, :id => @user.to_param, :user => {:name => 'Kermit'} |
| 55 | 55 | response.should redirect_to(user_path(@user)) |
| 56 | 56 | end |
| 57 | - | |
| 57 | + | |
| 58 | 58 | it "should not be able to become an admin" do |
| 59 | 59 | put :update, :id => @user.to_param, :user => {:admin => true} |
| 60 | 60 | @user.reload.admin.should be_false |
| ... | ... | @@ -65,8 +65,8 @@ describe UsersController do |
| 65 | 65 | @user.reload.per_page.should == 555 |
| 66 | 66 | end |
| 67 | 67 | end |
| 68 | - | |
| 69 | - context "when the update is unsuccessful" do | |
| 68 | + | |
| 69 | + context "when the update is unsuccessful" do | |
| 70 | 70 | it "renders the edit page" do |
| 71 | 71 | put :update, :id => @user.to_param, :user => {:name => nil} |
| 72 | 72 | response.should render_template(:edit) |
| ... | ... | @@ -74,7 +74,7 @@ describe UsersController do |
| 74 | 74 | end |
| 75 | 75 | end |
| 76 | 76 | end |
| 77 | - | |
| 77 | + | |
| 78 | 78 | context 'Signed in as an admin' do |
| 79 | 79 | before do |
| 80 | 80 | @user = Factory(:admin) |
| ... | ... | @@ -89,7 +89,7 @@ describe UsersController do |
| 89 | 89 | assigns(:users).size.should == 2 |
| 90 | 90 | end |
| 91 | 91 | end |
| 92 | - | |
| 92 | + | |
| 93 | 93 | context "GET /users/:id" do |
| 94 | 94 | it 'finds the user' do |
| 95 | 95 | user = Factory(:user) |
| ... | ... | @@ -97,7 +97,7 @@ describe UsersController do |
| 97 | 97 | assigns(:user).should == user |
| 98 | 98 | end |
| 99 | 99 | end |
| 100 | - | |
| 100 | + | |
| 101 | 101 | context "GET /users/new" do |
| 102 | 102 | it 'assigns a new user' do |
| 103 | 103 | get :new |
| ... | ... | @@ -105,7 +105,7 @@ describe UsersController do |
| 105 | 105 | assigns(:user).should be_new_record |
| 106 | 106 | end |
| 107 | 107 | end |
| 108 | - | |
| 108 | + | |
| 109 | 109 | context "GET /users/:id/edit" do |
| 110 | 110 | it 'finds the user' do |
| 111 | 111 | user = Factory(:user) |
| ... | ... | @@ -113,18 +113,18 @@ describe UsersController do |
| 113 | 113 | assigns(:user).should == user |
| 114 | 114 | end |
| 115 | 115 | end |
| 116 | - | |
| 116 | + | |
| 117 | 117 | context "POST /users" do |
| 118 | 118 | context "when the create is successful" do |
| 119 | 119 | before do |
| 120 | 120 | @attrs = {:user => Factory.attributes_for(:user)} |
| 121 | 121 | end |
| 122 | - | |
| 122 | + | |
| 123 | 123 | it "sets a message to display" do |
| 124 | 124 | post :create, @attrs |
| 125 | 125 | request.flash[:success].should include('part of the team') |
| 126 | 126 | end |
| 127 | - | |
| 127 | + | |
| 128 | 128 | it "redirects to the user's page" do |
| 129 | 129 | post :create, @attrs |
| 130 | 130 | response.should redirect_to(user_path(assigns(:user))) |
| ... | ... | @@ -142,76 +142,76 @@ describe UsersController do |
| 142 | 142 | User.last.authentication_token.should_not be_blank |
| 143 | 143 | end |
| 144 | 144 | end |
| 145 | - | |
| 145 | + | |
| 146 | 146 | context "when the create is unsuccessful" do |
| 147 | 147 | before do |
| 148 | 148 | @user = Factory(:user) |
| 149 | 149 | User.should_receive(:new).and_return(@user) |
| 150 | 150 | @user.should_receive(:save).and_return(false) |
| 151 | 151 | end |
| 152 | - | |
| 152 | + | |
| 153 | 153 | it "renders the new page" do |
| 154 | 154 | post :create |
| 155 | 155 | response.should render_template(:new) |
| 156 | 156 | end |
| 157 | 157 | end |
| 158 | 158 | end |
| 159 | - | |
| 159 | + | |
| 160 | 160 | context "PUT /users/:id" do |
| 161 | 161 | context "when the update is successful" do |
| 162 | 162 | before do |
| 163 | 163 | @user = Factory(:user) |
| 164 | 164 | end |
| 165 | - | |
| 165 | + | |
| 166 | 166 | it "sets a message to display" do |
| 167 | 167 | put :update, :id => @user.to_param, :user => {:name => 'Kermit'} |
| 168 | 168 | request.flash[:success].should include('updated') |
| 169 | 169 | end |
| 170 | - | |
| 170 | + | |
| 171 | 171 | it "redirects to the user's page" do |
| 172 | 172 | put :update, :id => @user.to_param, :user => {:name => 'Kermit'} |
| 173 | 173 | response.should redirect_to(user_path(@user)) |
| 174 | 174 | end |
| 175 | - | |
| 175 | + | |
| 176 | 176 | it "should be able to make user an admin" do |
| 177 | 177 | put :update, :id => @user.to_param, :user => {:admin => true} |
| 178 | 178 | response.should be_redirect |
| 179 | 179 | User.find(assigns(:user).to_param).admin.should be_true |
| 180 | 180 | end |
| 181 | 181 | end |
| 182 | - | |
| 182 | + | |
| 183 | 183 | context "when the update is unsuccessful" do |
| 184 | 184 | before do |
| 185 | 185 | @user = Factory(:user) |
| 186 | 186 | end |
| 187 | - | |
| 187 | + | |
| 188 | 188 | it "renders the edit page" do |
| 189 | 189 | put :update, :id => @user.to_param, :user => {:name => nil} |
| 190 | 190 | response.should render_template(:edit) |
| 191 | 191 | end |
| 192 | 192 | end |
| 193 | 193 | end |
| 194 | - | |
| 194 | + | |
| 195 | 195 | context "DELETE /users/:id" do |
| 196 | 196 | before do |
| 197 | 197 | @user = Factory(:user) |
| 198 | 198 | end |
| 199 | - | |
| 199 | + | |
| 200 | 200 | it "destroys the user" do |
| 201 | 201 | delete :destroy, :id => @user.id |
| 202 | 202 | User.where(:id => @user.id).first.should be_nil |
| 203 | 203 | end |
| 204 | - | |
| 204 | + | |
| 205 | 205 | it "redirects to the users index page" do |
| 206 | 206 | delete :destroy, :id => @user.id |
| 207 | 207 | response.should redirect_to(users_path) |
| 208 | 208 | end |
| 209 | - | |
| 209 | + | |
| 210 | 210 | it "sets a message to display" do |
| 211 | 211 | delete :destroy, :id => @user.id |
| 212 | 212 | request.flash[:success].should include('no longer part of your team') |
| 213 | 213 | end |
| 214 | 214 | end |
| 215 | - | |
| 215 | + | |
| 216 | 216 | end |
| 217 | 217 | end | ... | ... |
spec/models/deploy_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe Deploy do |
| 4 | - | |
| 4 | + | |
| 5 | 5 | context 'validations' do |
| 6 | 6 | it 'requires a username' do |
| 7 | 7 | deploy = Factory.build(:deploy, :username => nil) |
| 8 | 8 | deploy.should_not be_valid |
| 9 | 9 | deploy.errors[:username].should include("can't be blank") |
| 10 | 10 | end |
| 11 | - | |
| 11 | + | |
| 12 | 12 | it 'requires an environment' do |
| 13 | 13 | deploy = Factory.build(:deploy, :environment => nil) |
| 14 | 14 | deploy.should_not be_valid |
| 15 | 15 | deploy.errors[:environment].should include("can't be blank") |
| 16 | 16 | end |
| 17 | 17 | end |
| 18 | - | |
| 18 | + | |
| 19 | 19 | context 'being created' do |
| 20 | 20 | it 'should send an email notification' do |
| 21 | 21 | Mailer.should_receive(:deploy_notification). |
| 22 | 22 | and_return(mock('email', :deliver => true)) |
| 23 | 23 | Factory(:deploy, :app => Factory(:app_with_watcher)) |
| 24 | 24 | end |
| 25 | - | |
| 25 | + | |
| 26 | 26 | context 'when the app has resolve_errs_on_deploy set to false' do |
| 27 | 27 | it 'should not resolve the apps errs' do |
| 28 | 28 | app = Factory(:app, :resolve_errs_on_deploy => false) |
| ... | ... | @@ -31,7 +31,7 @@ describe Deploy do |
| 31 | 31 | app.reload.errs.none?{|err| err.resolved?}.should == true |
| 32 | 32 | end |
| 33 | 33 | end |
| 34 | - | |
| 34 | + | |
| 35 | 35 | context 'when the app has resolve_errs_on_deploy set to true' do |
| 36 | 36 | it 'should resolve the apps errs that were in the same environment' do |
| 37 | 37 | app = Factory(:app, :resolve_errs_on_deploy => true) |
| ... | ... | @@ -50,5 +50,5 @@ describe Deploy do |
| 50 | 50 | end |
| 51 | 51 | end |
| 52 | 52 | end |
| 53 | - | |
| 53 | + | |
| 54 | 54 | end | ... | ... |
spec/models/user_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe User do |
| 4 | - | |
| 4 | + | |
| 5 | 5 | context 'validations' do |
| 6 | 6 | it 'require that a name is present' do |
| 7 | 7 | user = Factory.build(:user, :name => nil) |
| ... | ... | @@ -9,16 +9,16 @@ describe User do |
| 9 | 9 | user.errors[:name].should include("can't be blank") |
| 10 | 10 | end |
| 11 | 11 | end |
| 12 | - | |
| 12 | + | |
| 13 | 13 | context 'Watchers' do |
| 14 | - | |
| 14 | + | |
| 15 | 15 | it 'has many watchers' do |
| 16 | 16 | user = Factory(:user) |
| 17 | 17 | watcher = Factory(:user_watcher, :user => user) |
| 18 | 18 | user.watchers.should_not be_empty |
| 19 | 19 | user.watchers.should include(watcher) |
| 20 | 20 | end |
| 21 | - | |
| 21 | + | |
| 22 | 22 | it "destroys any related watchers when it is destroyed" do |
| 23 | 23 | user = Factory(:user) |
| 24 | 24 | app = Factory(:app) |
| ... | ... | @@ -27,7 +27,7 @@ describe User do |
| 27 | 27 | user.destroy |
| 28 | 28 | app.reload.watchers.should_not include(watcher) |
| 29 | 29 | end |
| 30 | - | |
| 30 | + | |
| 31 | 31 | it "has many apps through watchers" do |
| 32 | 32 | user = Factory(:user) |
| 33 | 33 | watched_app = Factory(:app) |
| ... | ... | @@ -36,7 +36,7 @@ describe User do |
| 36 | 36 | user.apps.all.should include(watched_app) |
| 37 | 37 | user.apps.all.should_not include(unwatched_app) |
| 38 | 38 | end |
| 39 | - | |
| 39 | + | |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | context "First user" do |
| ... | ... | @@ -47,5 +47,5 @@ describe User do |
| 47 | 47 | User.first.admin.should be_true |
| 48 | 48 | end |
| 49 | 49 | end |
| 50 | - | |
| 50 | + | |
| 51 | 51 | end | ... | ... |
spec/models/watcher_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe Watcher do |
| 4 | - | |
| 4 | + | |
| 5 | 5 | context 'validations' do |
| 6 | 6 | it 'requires an email address or an associated user' do |
| 7 | 7 | watcher = Factory.build(:watcher, :email => nil, :user => nil) |
| 8 | 8 | watcher.should_not be_valid |
| 9 | 9 | watcher.errors[:base].should include("You must specify either a user or an email address") |
| 10 | - | |
| 10 | + | |
| 11 | 11 | watcher.email = 'watcher@example.com' |
| 12 | 12 | watcher.should be_valid |
| 13 | - | |
| 13 | + | |
| 14 | 14 | watcher.email = nil |
| 15 | 15 | watcher.should_not be_valid |
| 16 | - | |
| 16 | + | |
| 17 | 17 | watcher.user = Factory(:user) |
| 18 | 18 | watcher.watcher_type = 'user' |
| 19 | 19 | watcher.should be_valid |
| 20 | 20 | end |
| 21 | 21 | end |
| 22 | - | |
| 22 | + | |
| 23 | 23 | context 'address' do |
| 24 | 24 | it "returns the user's email address if there is a user" do |
| 25 | 25 | user = Factory(:user, :email => 'foo@bar.com') |
| 26 | 26 | watcher = Factory(:user_watcher, :user => user) |
| 27 | 27 | watcher.address.should == 'foo@bar.com' |
| 28 | 28 | end |
| 29 | - | |
| 29 | + | |
| 30 | 30 | it "returns the email if there is no user" do |
| 31 | 31 | watcher = Factory(:watcher, :email => 'widgets@acme.com') |
| 32 | 32 | watcher.address.should == 'widgets@acme.com' |
| 33 | 33 | end |
| 34 | 34 | end |
| 35 | - | |
| 35 | + | |
| 36 | 36 | end | ... | ... |
spec/spec_helper.rb
| ... | ... | @@ -13,11 +13,11 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} |
| 13 | 13 | RSpec.configure do |config| |
| 14 | 14 | config.mock_with :rspec |
| 15 | 15 | config.include Devise::TestHelpers, :type => :controller |
| 16 | - | |
| 16 | + | |
| 17 | 17 | config.filter_run :focused => true |
| 18 | 18 | config.run_all_when_everything_filtered = true |
| 19 | 19 | config.alias_example_to :fit, :focused => true |
| 20 | - | |
| 20 | + | |
| 21 | 21 | config.before(:each) do |
| 22 | 22 | DatabaseCleaner[:mongoid].strategy = :truncation |
| 23 | 23 | DatabaseCleaner.clean | ... | ... |
spec/support/macros.rb
| ... | ... | @@ -12,12 +12,12 @@ def it_requires_authentication(options = {}) |
| 12 | 12 | :params => {:id => '4c6c760494df2a18cc000015'} |
| 13 | 13 | } |
| 14 | 14 | options.reverse_merge!(default_options) |
| 15 | - | |
| 15 | + | |
| 16 | 16 | context 'when signed out' do |
| 17 | 17 | before do |
| 18 | 18 | sign_out :user |
| 19 | 19 | end |
| 20 | - | |
| 20 | + | |
| 21 | 21 | options[:for].each do |action, method| |
| 22 | 22 | it "#{method.to_s.upcase} #{action} redirects to the sign in page" do |
| 23 | 23 | send(method, action, options[:params]) |
| ... | ... | @@ -41,13 +41,13 @@ def it_requires_admin_privileges(options = {}) |
| 41 | 41 | :params => {:id => 'dummyid'} |
| 42 | 42 | } |
| 43 | 43 | options.reverse_merge!(default_options) |
| 44 | - | |
| 44 | + | |
| 45 | 45 | context 'when signed in as a regular user' do |
| 46 | 46 | before do |
| 47 | 47 | sign_out :user |
| 48 | 48 | sign_in Factory(:user) |
| 49 | 49 | end |
| 50 | - | |
| 50 | + | |
| 51 | 51 | options[:for].each do |action, method| |
| 52 | 52 | it "#{method.to_s.upcase} #{action} redirects to the root path" do |
| 53 | 53 | send(method, action, options[:params]) | ... | ... |