Navigation Menu

Skip to content

Commit

Permalink
Refactor Images::Options class into it's own file
Browse files Browse the repository at this point in the history
Add reset! class method to reset the Images::Options class to it's default values
Images::Options will reset after and before each spec
  • Loading branch information
Jamie Winsor committed Sep 7, 2011
1 parent b5ac6d4 commit 85d2314
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
33 changes: 33 additions & 0 deletions images/lib/refinery/images/options.rb
@@ -0,0 +1,33 @@
module Refinery
module Images
class Options
include Rails::Railtie::Configurable

DEFAULT_MAX_IMAGE_SIZE = 5242880
DEFAULT_PAGES_PER_DIALOG = 18
DEFAULT_PAGES_PER_DIALOG_THAT_HAVE_SIZE_OPTIONS = 12
DEFAULT_PAGES_PER_ADMIN_INDEX = 20

cattr_accessor :max_image_size
self.max_image_size = DEFAULT_MAX_IMAGE_SIZE

cattr_accessor :pages_per_dialog
self.pages_per_dialog = DEFAULT_PAGES_PER_DIALOG

cattr_accessor :pages_per_dialog_that_have_size_options
self.pages_per_dialog_that_have_size_options = DEFAULT_PAGES_PER_DIALOG_THAT_HAVE_SIZE_OPTIONS

cattr_accessor :pages_per_admin_index
self.pages_per_admin_index = DEFAULT_PAGES_PER_ADMIN_INDEX

class << self
def reset!
self.max_image_size = DEFAULT_MAX_IMAGE_SIZE
self.pages_per_dialog = DEFAULT_PAGES_PER_DIALOG
self.pages_per_dialog_that_have_size_options = DEFAULT_PAGES_PER_DIALOG_THAT_HAVE_SIZE_OPTIONS
self.pages_per_admin_index = DEFAULT_PAGES_PER_ADMIN_INDEX
end
end
end
end
end
17 changes: 1 addition & 16 deletions images/lib/refinerycms-images.rb
Expand Up @@ -7,22 +7,7 @@ module Refinery
module Images
autoload :Dragonfly, 'refinery/images/dragonfly'
autoload :Validators, 'refinery/images/validators'

class Options
include Rails::Railtie::Configurable

cattr_accessor :max_image_size
self.max_image_size = 5242880

cattr_accessor :pages_per_dialog
self.pages_per_dialog = 18

cattr_accessor :pages_per_dialog_that_have_size_options
self.pages_per_dialog_that_have_size_options = 12

cattr_accessor :pages_per_admin_index
self.pages_per_admin_index = 20
end
autoload :Options, 'refinery/images/options'

class << self
attr_accessor :root
Expand Down
15 changes: 15 additions & 0 deletions images/spec/lib/refinery/images/options.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

module Refinery
describe Images::Options do
describe ".reset!" do
it "should set options back to their default values" do
Images::Options.max_image_size.should == Images::Options::DEFAULT_MAX_IMAGE_SIZE
Images::Options.max_image_size += 1
Images::Options.max_image_size.should_not == Images::Options::DEFAULT_MAX_IMAGE_SIZE
Images::Options.reset!
Images::Options.max_image_size.should == Images::Options::DEFAULT_MAX_IMAGE_SIZE
end
end
end
end
8 changes: 0 additions & 8 deletions images/spec/requests/refinery/admin/images_spec.rb
Expand Up @@ -3,14 +3,6 @@
module Refinery
describe "AdminImages" do
login_refinery_user

before(:all) do
@max_image_size = Images::Options.max_image_size
end

after(:all) do
Images::Options.max_image_size = @max_image_size
end

context "when no images" do
it "invites to add one" do
Expand Down
8 changes: 8 additions & 0 deletions spec/support/refinery.rb
Expand Up @@ -5,4 +5,12 @@
RSpec.configure do |config|
config.extend Refinery::Testing::ControllerMacros::Authentication, :type => :controller
config.extend Refinery::Testing::RequestMacros::Authentication, :type => :request

config.before(:each) do
Refinery::Images::Options.reset!
end

config.after(:each) do
Refinery::Images::Options.reset!
end
end

0 comments on commit 85d2314

Please sign in to comment.