diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 2117398..86124d9 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -1,8 +1,11 @@ class CmsController < MyProfileController - define_option :page_class, Article - - protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] + # FIXME add the access control again + # protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] + + def view + @document = profile.documents.find(params[:id]) + end protected diff --git a/app/models/article.rb b/app/models/article.rb index 9b93df4..08e9ac3 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,14 +1,12 @@ class Article < ActiveRecord::Base + belongs_to :profile + validates_presence_of :profile_id, :name, :slug, :path + acts_as_taggable acts_as_filesystem acts_as_versioned - def profile(reload = false) - @profile = nil if reload - @profile ||= Profile.find_by_identifier(self.full_path.split(/\//).first) - end - end diff --git a/app/models/profile.rb b/app/models/profile.rb index 40e189b..4b1df3d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -109,7 +109,8 @@ class Profile < ActiveRecord::Base # +limit+ is the maximum number of documents to be returned. It defaults to # 10. def recent_documents(limit = 10) - homepage.children.find(:all, :limit => limit, :order => 'created_on desc') + # FIXME not like this anymore + raise 'needs to be rewritten' end def superior_instance diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml new file mode 100644 index 0000000..4584344 --- /dev/null +++ b/app/views/cms/view.rhtml @@ -0,0 +1,3 @@ +<%# FIXME %> + +

<%= @document.title %>

diff --git a/config/environment.rb b/config/environment.rb index b23854c..98c83eb 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -77,4 +77,4 @@ Tag.hierarchical = true # string transliteration require 'noosfero/transliterations' -require 'acts_as_versioned' +require 'acts_as_filesystem' diff --git a/db/migrate/007_create_articles.rb b/db/migrate/007_create_articles.rb index 0c4ae28..5864334 100644 --- a/db/migrate/007_create_articles.rb +++ b/db/migrate/007_create_articles.rb @@ -6,6 +6,7 @@ class CreateArticles < ActiveRecord::Migration t.column :name, :string t.column :slug, :string t.column :path, :text, :default => '' + t.column :parent_id, :integer # acts as tree included # main data t.column :body, :text @@ -13,14 +14,11 @@ class CreateArticles < ActiveRecord::Migration # belongs to profile t.column :profile_id, :integer - # acts as tree - t.column :parent_id, :integer - # keep track of timestamps t.column :updated_on, :datetime t.column :created_on, :datetime - # versioning stuff + # acts as versioned t.column :version, :integer t.column :lock_version, :integer end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index d74782c..cf72e63 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -11,7 +11,22 @@ class CmsControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end - def test_missing - flunk 'need to add some tests for CmsController ' + attr_reader :profile + + should 'list top level documents on index' do + flunk 'not yet' + end + + should 'be able to view a particular document' do + flunk 'not yet' + end + + should 'be able to edit a document' do + flunk 'not yet' + end + + should 'be able to save a save a document' do + flunk 'not yet' end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 869b1c7..ffce196 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -2,37 +2,53 @@ require File.dirname(__FILE__) + '/../test_helper' class ArticleTest < Test::Unit::TestCase - def test_should_use_keywords_as_tags - article = Article.new - article.title = 'a test article' - article.body = 'lalala' - article.parent = Article.find_by_path('ze') - article.keywords = 'one, two, three' - article.save! - - assert article.has_keyword?('one') - assert article.has_keyword?('two') - assert article.has_keyword?('three') + def setup + @profile = create_user('testing').person end + attr_reader :profile - should 'have an associated profile' do - # FIXME this is now wrong - article = Article.new(:title => 'someuser', :body => "some text") - article.save! + should 'have and require an associated profile' do + a = Article.new + a.valid? + assert a.errors.invalid?(:profile_id) - Profile.expects(:find_by_identifier).with("someuser") - article.profile + a.profile = profile + a.valid? + assert !a.errors.invalid?(:profile_id) end - should 'get associated profile from name of root page' do - article = Article.new(:title => "test article", :body => 'some sample text') - article.parent = Article.find_by_path('ze') - article.save! + should 'require values for name, slug and path' do + a = Article.new + a.valid? + assert a.errors.invalid?(:name) + assert a.errors.invalid?(:slug) + assert a.errors.invalid?(:path) + + a.name = 'my article' + a.valid? + assert !a.errors.invalid?(:name) + assert !a.errors.invalid?(:name) + assert !a.errors.invalid?(:path) + end + + should 'act as versioned' do + a = Article.create!(:name => 'my article', :body => 'my text', :profile_id => profile.id) + assert_equal 1, a.versions.size + a.name = 'some other name' + a.save! + assert_equal 2, a.versions.size + end - assert_equal 'ze/test-article', article.full_path + should 'act as taggable' do + a = Article.create!(:name => 'my article', :profile_id => profile.id) + a.tag_list = ['one', 'two'] + tags = a.tag_list.names + assert tags.include?('one') + assert tags.include?('two') + end - Profile.expects(:find_by_identifier).with("ze") - article.profile + should 'act as filesystem' do + flunk 'not yet' end end diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb index 1fde71e..840d5e4 100644 --- a/test/unit/category_test.rb +++ b/test/unit/category_test.rb @@ -1,5 +1,6 @@ require File.dirname(__FILE__) + '/../test_helper' +# FIXME move the filesystem-related tests out here class CategoryTest < Test::Unit::TestCase def setup -- libgit2 0.21.2