Skip to content

Commit

Permalink
updated specs, added exportable_models cattr_accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Sep 24, 2010
1 parent 17f7dcd commit f1d9824
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 36 deletions.
4 changes: 3 additions & 1 deletion vendor/extensions/exporter/README
@@ -1,3 +1,5 @@
= Exporter

Export your models to YAML at yoursite.com/admin/export
Export your models to YAML at yoursite.com/admin/export

If you want to add models for exporting, add them to the Radiant::Exporter.exportable_models array.
20 changes: 0 additions & 20 deletions vendor/extensions/exporter/Rakefile
@@ -1,23 +1,3 @@
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "radiant-exporter-extension"
gem.summary = %Q{Exporter Extension for Radiant CMS}
gem.description = %Q{Describe your extension here}
gem.email = "your email"
gem.homepage = "http://yourwebsite.com/exporter"
gem.authors = ["Your Name"]
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
rescue LoadError
puts "Jeweler (or a dependency) not available. This is only required if you plan to package exporter as a gem."
end

# In rails 1.2, plugins aren't available in the path until they're loaded.
# Check to see if the rspec plugin is installed first and require
# it if it is. If not, use the gem version.

# Determine where the RSpec plugin is by loading the boot
unless defined? RADIANT_ROOT
ENV["RAILS_ENV"] = "test"
case
Expand Down
5 changes: 4 additions & 1 deletion vendor/extensions/exporter/app/models/radiant/exporter.rb
@@ -1,8 +1,11 @@
module Radiant
class Exporter
cattr_accessor :exportable_models
@@exportable_models = [Radiant::Config, User, Page, PagePart, PageField, Snippet, Layout]

def self.export
hash = {}
[Radiant::Config, User, Page, PagePart, PageField, Snippet, Layout].each do |klass|
@@exportable_models.each do |klass|
hash[klass.name.pluralize] = klass.find(:all).inject({}) { |h, record| h[record.id.to_i] = record.attributes; h }
end
hash.to_yaml
Expand Down
30 changes: 16 additions & 14 deletions vendor/extensions/exporter/spec/models/radiant/exporter_spec.rb
Expand Up @@ -2,24 +2,26 @@

describe Radiant::Exporter do
dataset :pages_with_layouts, :users_and_pages, :snippets

before :each do
@exporter = Radiant::Exporter
@output = @exporter.export
@hash = YAML::load(@output)
@classes = ['Radiant::Configs', 'Users', 'Pages', 'PageParts', 'Snippets', 'Layouts', 'PageFields']
end

it "should output a string" do
@output.should be_kind_of(String)
end
let(:exporter){ Radiant::Exporter }
let(:exported_content){ exporter.export }
let(:exported_hash){ YAML::load(exported_content) }
subject { exporter }

it "should output all Radiant models" do
@classes.all? { |c| @hash.has_key?(c) }.should be_true
specify{ exported_content.should be_kind_of(String) }

it "should output all exportable_models with pluralized class names as keys" do
exporter.exportable_models.all? { |c| exported_hash.has_key?(c.to_s.pluralize) }.should be_true
end

it "should output the models by id as hashes" do
@hash['Pages'][page_id(:home)]['title'].should == pages(:home).title
@hash['Users'][user_id(:admin)]['name'].should == users(:admin).name
exported_hash['Pages'][page_id(:home)]['title'].should == pages(:home).title
exported_hash['Users'][user_id(:admin)]['name'].should == users(:admin).name
end

its(:exportable_models){ should == [Radiant::Config, User, Page, PagePart, PageField, Snippet, Layout] }
it "should allow setting exportable_models" do
exporter.exportable_models = [Page]
exporter.exportable_models.should == [Page]
end
end

0 comments on commit f1d9824

Please sign in to comment.