aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/admin_public_body_controller_spec.rb
blob: 3d41fd9f75f58c97bd5226779f7c1b0f36b5c348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require File.dirname(__FILE__) + '/../spec_helper'

describe AdminPublicBodyController, "when administering public bodies" do
    integrate_views
    fixtures :public_bodies
  
    it "shows the index page" do
        get :index
    end

    it "searches for 'humpa'" do
        get :index, :query => "humpa"
        assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ]
    end

    it "shows a public body" do
        get :show, :id => 2
    end

    it "creates a new public body" do
        PublicBody.count.should == 2
        post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
        PublicBody.count.should == 3
    end

    it "edits a public body" do
        get :edit, :id => 2
    end

    it "saves edits to a public body" do
        public_bodies(:humpadink_public_body).name.should == "Department for Humpadinking"
        post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' } }
        response.flash[:notice].should include('successful')
        pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
        pb.name.should == "Renamed"
    end

    it "destroy a public body" do
        PublicBody.count.should == 2
        post :destroy, { :id => 3 }
        PublicBody.count.should == 1
    end


end
s="w"> to_s if defined?(RAILS_ROOT) path.to_s.sub(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') else path.to_s end end def to_str path.to_str end def ==(path) to_str == path.to_str end def eql?(path) to_str == path.to_str end # Returns a ActionView::Template object for the given path string. The # input path should be relative to the view path directory, # +hello/index.html.erb+. This method also has a special exception to # match partial file names without a handler extension. So # +hello/index.html+ will match the first template it finds with a # known template extension, +hello/index.html.erb+. Template extensions # should not be confused with format extensions +html+, +js+, +xml+, # etc. A format must be supplied to match a formated file. +hello/index+ # will never match +hello/index.html.erb+. def [](path) end def load! end def self.new_and_loaded(path) returning new(path) do |path| path.load! end end private def relative_path_for_template_file(full_file_path) full_file_path.split("#{@path}/").last end end class EagerPath < Path def load! return if @loaded @paths = {} templates_in_path do |template| template.load! template.accessible_paths.each do |path| @paths[path] = template end end @paths.freeze @loaded = true end def [](path) load! unless @loaded @paths[path] end private def templates_in_path (Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |file| yield create_template(file) unless File.directory?(file) end end def create_template(file) Template.new(relative_path_for_template_file(file), self) end end extend TemplateHandlers extend ActiveSupport::Memoizable include Renderable # Templates that are exempt from layouts @@exempt_from_layout = Set.new([/\.rjs$/]) # Don't render layouts for templates with the given extensions. def self.exempt_from_layout(*extensions) regexps = extensions.collect do |extension| extension.is_a?(Regexp) ? extension : /\.#{Regexp.escape(extension.to_s)}$/ end @@exempt_from_layout.merge(regexps) end attr_accessor :template_path, :filename, :load_path, :base_path attr_accessor :locale, :name, :format, :extension delegate :to_s, :to => :path def initialize(template_path, load_path) @template_path = template_path.dup @load_path, @filename = load_path, File.join(load_path, template_path) @base_path, @name, @locale, @format, @extension = split(template_path) @base_path.to_s.gsub!(/\/$/, '') # Push to split method # Extend with partial super powers extend RenderablePartial if @name =~ /^_/ end def accessible_paths paths = [] if valid_extension?(extension) paths << path paths << path_without_extension if multipart? formats = format.split(".") paths << "#{path_without_format_and_extension}.#{formats.first}" paths << "#{path_without_format_and_extension}.#{formats.second}" end else # template without explicit template handler should only be reachable through its exact path paths << template_path end paths end def format_and_extension (extensions = [format, extension].compact.join(".")).blank? ? nil : extensions end memoize :format_and_extension def multipart? format && format.include?('.') end def content_type format.gsub('.', '/') end def mime_type Mime::Type.lookup_by_extension(format) if format && defined?(::Mime) end memoize :mime_type def path [base_path, [name, locale, format, extension].compact.join('.')].compact.join('/') end memoize :path def path_without_extension [base_path, [name, locale, format].compact.join('.')].compact.join('/') end memoize :path_without_extension def path_without_format_and_extension [base_path, [name, locale].compact.join('.')].compact.join('/') end memoize :path_without_format_and_extension def relative_path path = File.expand_path(filename) path.sub!(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') if defined?(RAILS_ROOT) path end memoize :relative_path def exempt_from_layout? @@exempt_from_layout.any? { |exempted| path =~ exempted } end def source File.read(filename) end memoize :source def method_segment relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord } end memoize :method_segment def render_template(view, local_assigns = {}) render(view, local_assigns) rescue Exception => e raise e unless filename if TemplateError === e e.sub_template_of(self) raise e else raise TemplateError.new(self, view.assigns, e) end end def load! freeze end private def valid_extension?(extension) !Template.registered_template_handler(extension).nil? end def valid_locale?(locale) I18n.available_locales.include?(locale.to_sym) end # Returns file split into an array # [base_path, name, locale, format, extension] def split(file) if m = file.to_s.match(/^(.*\/)?([^\.]+)\.(.*)$/) base_path = m[1] name = m[2] extensions = m[3] else return end locale = nil format = nil extension = nil if m = extensions.split(".") if valid_locale?(m[0]) && m[1] && valid_extension?(m[2]) # All three locale = m[0] format = m[1] extension = m[2] elsif m[0] && m[1] && valid_extension?(m[2]) # Multipart formats format = "#{m[0]}.#{m[1]}" extension = m[2] elsif valid_locale?(m[0]) && valid_extension?(m[1]) # locale and extension locale = m[0] extension = m[1] elsif valid_extension?(m[1]) # format and extension format = m[0] extension = m[1] elsif valid_extension?(m[0]) # Just extension extension = m[0] else # No extension format = m[0] end end [base_path, name, locale, format, extension] end end end