aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/refinery/blog/admin/categories_spec.rb
blob: 7a8df8cafbec2eec872904d4cc5aad31b308c6c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# encoding: utf-8
require 'spec_helper'

describe "Categories admin", type: :feature do
  refinery_login_with :refinery_user

  let(:title) { "lol" }

  it "can create categories" do
    visit refinery.admin_root_path

    within("nav#menu") { click_link "Blog" }
    within("nav.multilist") { click_link "Create new category" }

    fill_in "Title", :with => title
    click_button "Save"

    category = Refinery::Blog::Category.first
    expect(category.title).to eq(title)
  end

  context "with translations" do
    before do
      allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
      blog_page = Globalize.with_locale(:en) { FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog") }
      Globalize.with_locale(:ru) do
        blog_page.title = 'блог'
        blog_page.save
      end
    end

    describe "add a category with title for default locale" do
      before do
        Globalize.locale = :en
        visit refinery.blog_admin_posts_path
        click_link "Create new category"
        fill_in "Title", :with => "Testing Category"
        expect { click_button "Save" }.to change(Refinery::Blog::Category, :count).by(1)
        @c = Refinery::Blog::Category.by_title("Testing Category")
      end

      it "suceeds" do
        expect(page).to have_content("'#{@c.title}' was successfully added.")
        expect(Refinery::Blog::Category.count).to eq(1)
      end

      it "shows locale for category" do
        click_link "Manage"
        within "#category_#{@c.id}" do
          expect(page).to have_css(".locale_icon.en")
        end
      end

      it "shows up in blog page for default locale" do
        visit refinery.blog_root_path
        within "#categories" do
          expect(page).to have_selector('li')
        end
      end

      it "does not show up in blog page for secondary locale" do
        visit refinery.blog_root_path(:locale => :ru)
        expect(page).not_to have_selector('#categories')
      end

    end

    describe "add a category with title for secondary locale" do

      let(:ru_category_title) { 'категория' }

      before do
        visit refinery.blog_admin_posts_path
        click_link "Create new category"
        within "#switch_locale_picker" do
          click_link "RU"
        end
        fill_in "Title", :with => ru_category_title
        expect { click_button "Save" }.to change(Refinery::Blog::Category, :count).by(1)
        @c = Refinery::Blog::Category.by_title(ru_category_title)
      end

      it "suceeds" do
        expect(page).to have_content("'#{@c.title}' was successfully added.")
        expect(Refinery::Blog::Category.count).to eq(1)
      end

      it "shows locale for category" do
        click_link "Manage"
        within "#category_#{@c.id}" do
          expect(page).to have_css(".locale_icon.ru")
        end
      end

      it "does not show locale for primary locale" do
        click_link "Manage"
        within "#category_#{@c.id}" do
          expect(page).not_to have_css(".locale_icon.en")
        end
      end

      it "does not shows up in blog page for default locale" do
        visit refinery.blog_root_path
        expect(page).not_to have_selector('#categories')
      end

      it "shows up in blog page for secondary locale" do
        visit refinery.blog_root_path(:locale => :ru)
        within "#categories" do
          expect(page).to have_selector('li')
        end
      end


    end


  end
end