Sha256: bd1a4dc80ac78a98c0d075f0cdbad17cc0c7ac0b59de77814d7ae5c622842abf

Contents?: true

Size: 1.98 KB

Versions: 17

Compression:

Stored size: 1.98 KB

Contents

module RestAssured
  module RedirectRoutes
    def self.included(router)
      router.get '/redirects' do
        @redirects = Models::Redirect.ordered
        haml :'redirects/index'
      end

      router.get '/redirects/new' do
        @redirect = Models::Redirect.new
        haml :'redirects/new'
      end

      router.post '/redirects' do
        @redirect = Models::Redirect.create(params['redirect'] || { :pattern => params['pattern'], :to => params['to'] })

        if browser?
          if @redirect.errors.blank?
            flash[:notice] = "Redirect created"
            redirect '/redirects'
          else
            flash.now[:error] = "Crumps! " + @redirect.errors.full_messages.join("; ")
            haml :'redirects/new'
          end
        else
          if @redirect.errors.present?
            status 400
            body @redirect.errors.full_messages.join("\n")
          end
        end
      end

      router.get %r{/redirects/(\d+)/edit} do |id|
        @redirect = Models::Redirect.find(id)
        haml :'redirects/edit'
      end

      router.put %r{/redirects/(\d+)} do |id|
        @redirect = Models::Redirect.find(id)

        @redirect.update_attributes(params['redirect'])

        if @redirect.save
          flash[:notice] = 'Redirect updated'
          redirect '/redirects'
        else
          flash[:error] = 'Crumps! ' + @redirect.errors.full_messages.join("\n")
          haml :'redirects/edit'
        end
      end

      router.put '/redirects/reorder' do
        if params['redirect']
          if Models::Redirect.update_order(params['redirect'])
            'Changed'
          else
            'Crumps! It broke'
          end
        end
      end

      router.delete %r{/redirects/(\d+)} do |id|
        if Models::Redirect.destroy(id)
          flash[:notice] = 'Redirect deleted'
          redirect '/redirects'
        end
      end

      router.delete '/redirects/all' do
        status Models::Redirect.delete_all ? 200 : 500
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rest-assured-1.2.2 lib/rest-assured/routes/redirect.rb
rest-assured-1.2.1 lib/rest-assured/routes/redirect.rb
rest-assured-1.2.0 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.10 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.9 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.8 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.7 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.6 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.5 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.4 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.3 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.2 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.1 lib/rest-assured/routes/redirect.rb
rest-assured-1.1.0 lib/rest-assured/routes/redirect.rb
rest-assured-1.0.0 lib/rest-assured/routes/redirect.rb
rest-assured-1.0.0.rc2 lib/rest-assured/routes/redirect.rb
rest-assured-1.0.0.rc1 lib/rest-assured/routes/redirect.rb