Commit 1846267f58586d0540c5582ee2a8fa82df702659
1 parent
8110369e
Exists in
master
and in
29 other branches
ActionItem21: checkpoint
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@943 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
75 additions
and
40 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
1 | 1 | class CmsController < MyProfileController |
2 | 2 | |
3 | - define_option :page_class, Article | |
4 | - | |
5 | - protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] | |
3 | + # FIXME add the access control again | |
4 | + # protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] | |
5 | + | |
6 | + def view | |
7 | + @document = profile.documents.find(params[:id]) | |
8 | + end | |
6 | 9 | |
7 | 10 | protected |
8 | 11 | ... | ... |
app/models/article.rb
1 | 1 | class Article < ActiveRecord::Base |
2 | 2 | |
3 | + belongs_to :profile | |
4 | + validates_presence_of :profile_id, :name, :slug, :path | |
5 | + | |
3 | 6 | acts_as_taggable |
4 | 7 | |
5 | 8 | acts_as_filesystem |
6 | 9 | |
7 | 10 | acts_as_versioned |
8 | 11 | |
9 | - def profile(reload = false) | |
10 | - @profile = nil if reload | |
11 | - @profile ||= Profile.find_by_identifier(self.full_path.split(/\//).first) | |
12 | - end | |
13 | - | |
14 | 12 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -109,7 +109,8 @@ class Profile < ActiveRecord::Base |
109 | 109 | # +limit+ is the maximum number of documents to be returned. It defaults to |
110 | 110 | # 10. |
111 | 111 | def recent_documents(limit = 10) |
112 | - homepage.children.find(:all, :limit => limit, :order => 'created_on desc') | |
112 | + # FIXME not like this anymore | |
113 | + raise 'needs to be rewritten' | |
113 | 114 | end |
114 | 115 | |
115 | 116 | def superior_instance | ... | ... |
config/environment.rb
db/migrate/007_create_articles.rb
... | ... | @@ -6,6 +6,7 @@ class CreateArticles < ActiveRecord::Migration |
6 | 6 | t.column :name, :string |
7 | 7 | t.column :slug, :string |
8 | 8 | t.column :path, :text, :default => '' |
9 | + t.column :parent_id, :integer # acts as tree included | |
9 | 10 | |
10 | 11 | # main data |
11 | 12 | t.column :body, :text |
... | ... | @@ -13,14 +14,11 @@ class CreateArticles < ActiveRecord::Migration |
13 | 14 | # belongs to profile |
14 | 15 | t.column :profile_id, :integer |
15 | 16 | |
16 | - # acts as tree | |
17 | - t.column :parent_id, :integer | |
18 | - | |
19 | 17 | # keep track of timestamps |
20 | 18 | t.column :updated_on, :datetime |
21 | 19 | t.column :created_on, :datetime |
22 | 20 | |
23 | - # versioning stuff | |
21 | + # acts as versioned | |
24 | 22 | t.column :version, :integer |
25 | 23 | t.column :lock_version, :integer |
26 | 24 | end | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -11,7 +11,22 @@ class CmsControllerTest < Test::Unit::TestCase |
11 | 11 | @response = ActionController::TestResponse.new |
12 | 12 | end |
13 | 13 | |
14 | - def test_missing | |
15 | - flunk 'need to add some tests for CmsController ' | |
14 | + attr_reader :profile | |
15 | + | |
16 | + should 'list top level documents on index' do | |
17 | + flunk 'not yet' | |
18 | + end | |
19 | + | |
20 | + should 'be able to view a particular document' do | |
21 | + flunk 'not yet' | |
22 | + end | |
23 | + | |
24 | + should 'be able to edit a document' do | |
25 | + flunk 'not yet' | |
26 | + end | |
27 | + | |
28 | + should 'be able to save a save a document' do | |
29 | + flunk 'not yet' | |
16 | 30 | end |
31 | + | |
17 | 32 | end | ... | ... |
test/unit/article_test.rb
... | ... | @@ -2,37 +2,53 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class ArticleTest < Test::Unit::TestCase |
4 | 4 | |
5 | - def test_should_use_keywords_as_tags | |
6 | - article = Article.new | |
7 | - article.title = 'a test article' | |
8 | - article.body = 'lalala' | |
9 | - article.parent = Article.find_by_path('ze') | |
10 | - article.keywords = 'one, two, three' | |
11 | - article.save! | |
12 | - | |
13 | - assert article.has_keyword?('one') | |
14 | - assert article.has_keyword?('two') | |
15 | - assert article.has_keyword?('three') | |
5 | + def setup | |
6 | + @profile = create_user('testing').person | |
16 | 7 | end |
8 | + attr_reader :profile | |
17 | 9 | |
18 | - should 'have an associated profile' do | |
19 | - # FIXME this is now wrong | |
20 | - article = Article.new(:title => 'someuser', :body => "some text") | |
21 | - article.save! | |
10 | + should 'have and require an associated profile' do | |
11 | + a = Article.new | |
12 | + a.valid? | |
13 | + assert a.errors.invalid?(:profile_id) | |
22 | 14 | |
23 | - Profile.expects(:find_by_identifier).with("someuser") | |
24 | - article.profile | |
15 | + a.profile = profile | |
16 | + a.valid? | |
17 | + assert !a.errors.invalid?(:profile_id) | |
25 | 18 | end |
26 | 19 | |
27 | - should 'get associated profile from name of root page' do | |
28 | - article = Article.new(:title => "test article", :body => 'some sample text') | |
29 | - article.parent = Article.find_by_path('ze') | |
30 | - article.save! | |
20 | + should 'require values for name, slug and path' do | |
21 | + a = Article.new | |
22 | + a.valid? | |
23 | + assert a.errors.invalid?(:name) | |
24 | + assert a.errors.invalid?(:slug) | |
25 | + assert a.errors.invalid?(:path) | |
26 | + | |
27 | + a.name = 'my article' | |
28 | + a.valid? | |
29 | + assert !a.errors.invalid?(:name) | |
30 | + assert !a.errors.invalid?(:name) | |
31 | + assert !a.errors.invalid?(:path) | |
32 | + end | |
33 | + | |
34 | + should 'act as versioned' do | |
35 | + a = Article.create!(:name => 'my article', :body => 'my text', :profile_id => profile.id) | |
36 | + assert_equal 1, a.versions.size | |
37 | + a.name = 'some other name' | |
38 | + a.save! | |
39 | + assert_equal 2, a.versions.size | |
40 | + end | |
31 | 41 | |
32 | - assert_equal 'ze/test-article', article.full_path | |
42 | + should 'act as taggable' do | |
43 | + a = Article.create!(:name => 'my article', :profile_id => profile.id) | |
44 | + a.tag_list = ['one', 'two'] | |
45 | + tags = a.tag_list.names | |
46 | + assert tags.include?('one') | |
47 | + assert tags.include?('two') | |
48 | + end | |
33 | 49 | |
34 | - Profile.expects(:find_by_identifier).with("ze") | |
35 | - article.profile | |
50 | + should 'act as filesystem' do | |
51 | + flunk 'not yet' | |
36 | 52 | end |
37 | 53 | |
38 | 54 | end | ... | ... |