diff options
| author | hukl <contact@smyck.org> | 2009-07-18 18:17:06 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-07-18 18:17:06 +0200 |
| commit | 144b18c5db61c53028177680295f3fc9d4e8711d (patch) | |
| tree | dfed99c6a59487af6279ce15c02dbc366328602d | |
| parent | aab86f2d2a0258a1347f39c1ee4081cd06bac56b (diff) | |
Test::Unit Fixtures can't handle globalize2's translated attributes which is why its impossible to set translated attributes via fixtures. Therefor I removed the page fixtures entirely and and made sure that a title is set to "Untitled" when it is not specified otherwise.
If a new node is created, its initial draft has "Untitled" set as title automatically.
Modified tests accordingly
| -rw-r--r-- | app/models/node.rb | 2 | ||||
| -rw-r--r-- | app/models/page.rb | 22 | ||||
| -rw-r--r-- | test/fixtures/pages.yml | 64 | ||||
| -rw-r--r-- | test/functional/nodes_controller_test.rb | 4 | ||||
| -rw-r--r-- | test/unit/node_test.rb | 4 | ||||
| -rw-r--r-- | test/unit/page_test.rb | 6 |
6 files changed, 61 insertions, 41 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 647a86a..2a82ba8 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -67,7 +67,7 @@ class Node < ActiveRecord::Base | |||
| 67 | end | 67 | end |
| 68 | 68 | ||
| 69 | def create_new_draft user | 69 | def create_new_draft user |
| 70 | empty_page = self.pages.create | 70 | empty_page = self.pages.create! |
| 71 | empty_page.user = user | 71 | empty_page.user = user |
| 72 | empty_page.save | 72 | empty_page.save |
| 73 | 73 | ||
diff --git a/app/models/page.rb b/app/models/page.rb index 49ac586..0a978ab 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -30,7 +30,8 @@ class Page < ActiveRecord::Base | |||
| 30 | belongs_to :user | 30 | belongs_to :user |
| 31 | 31 | ||
| 32 | # Filter | 32 | # Filter |
| 33 | before_save :rewrite_links_in_body | 33 | before_create :set_page_title |
| 34 | before_save :rewrite_links_in_body | ||
| 34 | 35 | ||
| 35 | # Security | 36 | # Security |
| 36 | attr_accessible :title, :abstract, :body, :template_name, :published_at | 37 | attr_accessible :title, :abstract, :body, :template_name, :published_at |
| @@ -168,16 +169,21 @@ class Page < ActiveRecord::Base | |||
| 168 | 169 | ||
| 169 | private | 170 | private |
| 170 | 171 | ||
| 172 | def set_page_title | ||
| 173 | if title.nil? | ||
| 174 | title = "Untitled" | ||
| 175 | end | ||
| 176 | end | ||
| 177 | |||
| 171 | def rewrite_links_in_body | 178 | def rewrite_links_in_body |
| 172 | begin | 179 | begin |
| 173 | if self.body | 180 | if self.body |
| 174 | tmp_body = "<div>#{self.body}</div>" | 181 | tmp_body = "<div>#{self.body}</div>" |
| 175 | xml_string = XML::Parser.string( tmp_body ) | 182 | xml_string = XML::Parser.string( tmp_body ) |
| 176 | xml_doc = xml_string.parse | 183 | xml_doc = xml_string.parse |
| 177 | links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") | 184 | links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") |
| 178 | 185 | locales = I18n.available_locales.reject {|l| l == :root} | |
| 179 | locales = I18n.available_locales.reject {|l| l == :root} | 186 | |
| 180 | |||
| 181 | links.each do |link| | 187 | links.each do |link| |
| 182 | unless locales.include? link[:href].slice(1,2).to_sym | 188 | unless locales.include? link[:href].slice(1,2).to_sym |
| 183 | link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") | 189 | link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") |
diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml index 271c494..686f173 100644 --- a/test/fixtures/pages.yml +++ b/test/fixtures/pages.yml | |||
| @@ -1,31 +1,37 @@ | |||
| 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
| 2 | 2 | ||
| 3 | one: | 3 | # one: |
| 4 | id: 1 | 4 | # id: 1 |
| 5 | revision: 1 | 5 | # revision: 1 |
| 6 | node_id: 2 | 6 | # node_id: 2 |
| 7 | 7 | # title: "first" | |
| 8 | two: | 8 | # |
| 9 | id: 2 | 9 | # two: |
| 10 | revision: 1 | 10 | # id: 2 |
| 11 | node_id: 4 | 11 | # revision: 1 |
| 12 | 12 | # node_id: 4 | |
| 13 | draft1: | 13 | # title: "second" |
| 14 | id: 100 | 14 | # |
| 15 | revision: 1 | 15 | # draft1: |
| 16 | node_id: 2 | 16 | # id: 100 |
| 17 | 17 | # revision: 1 | |
| 18 | draft2: | 18 | # node_id: 2 |
| 19 | id: 101 | 19 | # title: "third" |
| 20 | revision: 1 | 20 | # |
| 21 | node_id: 3 | 21 | # draft2: |
| 22 | 22 | # id: 101 | |
| 23 | draft3: | 23 | # revision: 1 |
| 24 | id: 102 | 24 | # node_id: 3 |
| 25 | revision: 1 | 25 | # title: "fourth" |
| 26 | node_id: 4 | 26 | # |
| 27 | 27 | # draft3: | |
| 28 | draft4: | 28 | # id: 102 |
| 29 | id: 103 | 29 | # revision: 1 |
| 30 | revision: 1 | 30 | # node_id: 4 |
| 31 | node_id: 5 \ No newline at end of file | 31 | # title: "fifth" |
| 32 | # | ||
| 33 | # draft4: | ||
| 34 | # id: 103 | ||
| 35 | # revision: 1 | ||
| 36 | # node_id: 5 | ||
| 37 | # title: "sixth" \ No newline at end of file | ||
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index edc49b6..1c7e607 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb | |||
| @@ -5,6 +5,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 5 | include AuthenticatedTestHelper | 5 | include AuthenticatedTestHelper |
| 6 | 6 | ||
| 7 | def test_get_index | 7 | def test_get_index |
| 8 | Node.root.descendants.delete_all | ||
| 8 | login_as :quentin | 9 | login_as :quentin |
| 9 | get :index | 10 | get :index |
| 10 | assert_response :success | 11 | assert_response :success |
| @@ -26,6 +27,9 @@ class NodesControllerTest < ActionController::TestCase | |||
| 26 | login_as :quentin | 27 | login_as :quentin |
| 27 | 28 | ||
| 28 | node = Node.find_by_unique_name("fourth_child") | 29 | node = Node.find_by_unique_name("fourth_child") |
| 30 | node.pages.create | ||
| 31 | node.draft = node.pages.last | ||
| 32 | node.save | ||
| 29 | 33 | ||
| 30 | assert_equal 1, node.pages.length | 34 | assert_equal 1, node.pages.length |
| 31 | 35 | ||
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index e054887..ef298bb 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb | |||
| @@ -5,7 +5,11 @@ class NodeTest < ActiveSupport::TestCase | |||
| 5 | def setup | 5 | def setup |
| 6 | @root = Node.find(1) | 6 | @root = Node.find(1) |
| 7 | @first_child = Node.find(2) | 7 | @first_child = Node.find(2) |
| 8 | @first_child.pages.create! :title => "one" | ||
| 9 | @first_child.draft = @first_child.pages.last | ||
| 10 | @first_child.save | ||
| 8 | @second_child = Node.find(3) | 11 | @second_child = Node.find(3) |
| 12 | @second_child.pages.create! :title => "one" | ||
| 9 | 13 | ||
| 10 | @user1 = User.create :login => 'demo', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' | 14 | @user1 = User.create :login => 'demo', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' |
| 11 | @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' | 15 | @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' |
diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index 8c2fc95..a2083c0 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb | |||
| @@ -22,7 +22,7 @@ class PageTest < ActiveSupport::TestCase | |||
| 22 | d1.tag_list = "update" | 22 | d1.tag_list = "update" |
| 23 | d1.save | 23 | d1.save |
| 24 | n1.publish_draft! | 24 | n1.publish_draft! |
| 25 | 25 | ||
| 26 | d2 = n1.find_or_create_draft @user1 | 26 | d2 = n1.find_or_create_draft @user1 |
| 27 | n1.publish_draft! | 27 | n1.publish_draft! |
| 28 | 28 | ||
| @@ -30,7 +30,7 @@ class PageTest < ActiveSupport::TestCase | |||
| 30 | d3.tag_list = "update, pressemitteilung" | 30 | d3.tag_list = "update, pressemitteilung" |
| 31 | d3.save | 31 | d3.save |
| 32 | n2.publish_draft! | 32 | n2.publish_draft! |
| 33 | 33 | ||
| 34 | d4 = n2.find_or_create_draft @user1 | 34 | d4 = n2.find_or_create_draft @user1 |
| 35 | n2.publish_draft! | 35 | n2.publish_draft! |
| 36 | 36 | ||
| @@ -63,7 +63,7 @@ class PageTest < ActiveSupport::TestCase | |||
| 63 | I18n.locale = :de | 63 | I18n.locale = :de |
| 64 | 64 | ||
| 65 | d.body = before | 65 | d.body = before |
| 66 | d.save | 66 | d.save! |
| 67 | 67 | ||
| 68 | assert_equal after, d.body | 68 | assert_equal after, d.body |
| 69 | end | 69 | end |
