require File.dirname(__FILE__) + '/../spec_helper' describe "Globalize 2 Tags" do before do I18n.locale = "en" @page = Factory.create(:page) Factory.create(:romanian_page_translation, :page => @page) @page_part = Factory.create(:page_part, :page => @page) Factory.create(:romanian_page_part_translation, :page_part => @page_part) end describe "" do it "returns the current locale" do @page.should render("").as("en") end end describe "" do it "raises an error if tag is not included" do @page. should render(""). with_error("'locales' tag must include a 'normal' tag") end it "renders the list of codes supplied" do @page. should render(""). as("en ro") end it "prefers the between attribute when rendering the locales" do @page. should render(""). as("en|ro") end end describe "" do it "raises error if 'code' tag attribute is not set" do @page. should render(""). with_error("'code' must be set") end it "switches the locale" do @page. should render(""). as("Pagina Cool") end end describe "" do it "expands if the page's title is translated" do @page. should render(""). matching(/Cool Page \d*/) end end describe "" do it "expands if the page's title is not translated" do not_translated_page = Factory.create(:page, :title => "Not Translated Page") switch_locale("ro") do not_translated_page. should render(""). as("Not Translated Page") end end end describe "" do it "expands if the page's 'body' part is translated" do @page. should render(""). as("english content") end end describe " "Not Translated Page") not_translated_page_part = Factory.create(:page_part, :page => not_translated_page, :content => "not-translated") switch_locale("ro") do not_translated_page. should render(""). as("not-translated") end end end describe "" do it "renders the link with the current locale if 'locale' tag attribute is not set" do @page.should render("").matching(/Cool Page \d*\<\/a>/) end it "renders the link with the given locale if the 'locale' tag attribute is set" do @page.should render("").as("Pagina Cool") end end describe "" do before(:each) do @parent = Factory.create(:page) child_one = Factory.create(:child_page, :parent => @parent) Factory.create(:child_page, :parent => @parent) Factory.create(:romanian_page_translation, :page => child_one, :title => "Pagina 1") end it "filters the children by locale if 'locale' attribute is not set to false" do switch_locale(:ro) do @parent. should render(" "). as("Pagina 1 ") end end it "does not filter by locale if 'locale' attribute is set to false" do switch_locale(:ro) do @parent. should render(" "). matching(/Pagina 1 Child page \d*/) end end end if defined?(PaginateExtension) describe "" do before(:each) do @parent = Factory.create(:page) child_one = Factory.create(:child_page, :parent => @parent) Factory.create(:romanian_page_translation, :page => child_one, :title => "Pagina 1") (1..4).map{ |i| Factory.create(:child_page, :parent => @parent) } end it "filters the paginated children by locale if 'locale' tag attribute is not set to false" do @parent.save! switch_locale(:ro) do @parent. should render(""). as("Pagina 1") end end it "does not filter paginated children by locale if 'locale' tag attribute is set to false" do switch_locale(:ro) do @parent. should render(" "). matching(%r{Pagina 1 Child page \d*}) end end end end end