Skip to content

Commit

Permalink
Refactor Resource::PAGES_PER_DIALOG constant into Engine configurable…
Browse files Browse the repository at this point in the history
… option pages_per_dialog
  • Loading branch information
Jamie Winsor committed Sep 8, 2011
1 parent 66ef3fc commit ac88125
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
7 changes: 2 additions & 5 deletions resources/app/models/refinery/resource.rb
@@ -1,4 +1,4 @@
module ::Refinery
module Refinery
class Resource < ActiveRecord::Base
include Resources::Validators

Expand All @@ -12,9 +12,6 @@ class Resource < ActiveRecord::Base
# Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
acts_as_indexed :fields => [:file_name, :title, :type_of_content]

# when a dialog pops up with resources, how many resources per page should there be
PAGES_PER_DIALOG = 12

# when listing resources out in the admin area, how many resources should show per page
PAGES_PER_ADMIN_INDEX = 20

Expand All @@ -34,7 +31,7 @@ def title
class << self
# How many resources per page should be displayed?
def per_page(dialog = false)
dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
dialog ? Resources::Options.pages_per_dialog : PAGES_PER_ADMIN_INDEX
end

def create_resources(params)
Expand Down
@@ -1,4 +1,7 @@
Refinery::Resources::Options.configure do |config|
# Configures the maximum allowed upload size for a file upload
# config.max_file_size = <%= Refinery::Resources::Options::DEFAULT_MAX_FILE_SIZE %>

# Configure how many resources per page should be displayed when a dialog is presented that contains resources
config.pages_per_dialog = <%= Refinery::Resources::Options::DEFAULT_PAGES_PER_DIALOG %>
end
5 changes: 5 additions & 0 deletions resources/lib/refinery/resources/options.rb
Expand Up @@ -4,13 +4,18 @@ class Options
include Rails::Railtie::Configurable

DEFAULT_MAX_FILE_SIZE = 52428800
DEFAULT_PAGES_PER_DIALOG = 12

cattr_accessor :max_file_size
self.max_file_size = DEFAULT_MAX_FILE_SIZE

cattr_accessor :pages_per_dialog
self.pages_per_dialog = DEFAULT_PAGES_PER_DIALOG

class << self
def reset!
self.max_file_size = DEFAULT_MAX_FILE_SIZE
self.pages_per_dialog = DEFAULT_PAGES_PER_DIALOG
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions resources/spec/lib/refinery/resources/options_spec.rb
Expand Up @@ -10,6 +10,14 @@ module Refinery
Resources::Options.reset!
Resources::Options.max_file_size.should == Resources::Options::DEFAULT_MAX_FILE_SIZE
end

it "should set pages_per_dialog back to the default value" do
Resources::Options.pages_per_dialog.should == Resources::Options::DEFAULT_PAGES_PER_DIALOG
Resources::Options.pages_per_dialog += 1
Resources::Options.pages_per_dialog.should_not == Resources::Options::DEFAULT_PAGES_PER_DIALOG
Resources::Options.reset!
Resources::Options.pages_per_dialog.should == Resources::Options::DEFAULT_PAGES_PER_DIALOG
end
end
end
end
4 changes: 2 additions & 2 deletions resources/spec/models/refinery/resource_spec.rb
Expand Up @@ -46,8 +46,8 @@ module Refinery

describe ".per_page" do
context "dialog is true" do
it "returns resource count specified by PAGES_PER_DIALOG constant" do
Resource.per_page(true).should == Resource::PAGES_PER_DIALOG
it "returns resource count specified by Resources::Options.pages_per_dialog option" do
Resource.per_page(true).should == Resources::Options.pages_per_dialog
end
end

Expand Down

0 comments on commit ac88125

Please sign in to comment.