Skip to content

Commit 2cdafc8

Browse files
committed
Completed working features for inline translations
1 parent b262041 commit 2cdafc8

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

spec/features/article_composing_spec.rb

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
require 'spec_helper'
22

3-
feature 'Article composing' do
3+
feature 'Article localization features', :js do
44

55
given!(:current_user) { create(:user) }
66

77
before do
88
login_user(current_user)
99
end
1010

11-
scenario 'Create an article', :js do
11+
scenario 'Create an article' do
1212

1313
within(main_menubar) { click_link 'Articles' }
1414
within(action_bar) { click_link 'New Article' }
@@ -21,10 +21,50 @@
2121
end
2222

2323
page.should have_content 'Article was successfully created.'
24-
# Retrieve article from database
24+
25+
# Retrieve created article from database
2526
article = Article.first
2627
page.should have_content article.title
2728
page.should have_content article.body
2829
end
2930

31+
context 'Viewing article translations' do
32+
33+
given!(:article) { create(:localized_article) }
34+
35+
before do
36+
# Load article page
37+
ensure_on(admin_article_path(article))
38+
end
39+
40+
# See spec/dummy/app/admin/articles.rb
41+
scenario 'Viewing a translated article' do
42+
43+
# First row shows default locale with label title
44+
within first_table_row do
45+
page.should have_css 'th', text: 'TITLE'
46+
page.should have_css 'span.field-translation', text: article.title
47+
end
48+
# Second row shows italian title by default
49+
within second_table_row do
50+
page.should have_css 'th', text: 'ITALIAN TITLE'
51+
page.should have_css 'span.field-translation', text: article.translation_for(:it).title
52+
end
53+
54+
end
55+
56+
scenario 'Switch inline translations' do
57+
58+
# First row shows default locale with label title
59+
within first_table_row do
60+
page.should have_css 'th', text: 'TITLE'
61+
page.should have_css 'span.field-translation', text: article.title
62+
flag_link(:it).click # change shown translation
63+
page.should have_css 'span.field-translation', text: article.translation_for(:it).title
64+
end
65+
66+
end
67+
68+
end
69+
3070
end

spec/support/capybara_activeadmin_helpers.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ def submit_button
5555
find 'input[type="submit"]'
5656
end
5757

58+
# Return Nth table row
59+
def table_row_number(n)
60+
find "table tr:nth-child(#{n})"
61+
end
62+
63+
def first_table_row
64+
table_row_number(1)
65+
end
66+
67+
def second_table_row
68+
table_row_number(2)
69+
end
70+
71+
# Return the anchor element with flag class
72+
def flag_icon(locale = I18n.locale)
73+
find ".flag-#{locale}"
74+
end
75+
76+
# Return an a element used to trigger language switch using javascript
77+
def flag_link(locale = I18n.locale)
78+
# find the flag icon by class and go back to parent to get the link
79+
find(:xpath, %Q{.//img[contains(@class, "flag-#{locale}")]/..})
80+
end
81+
5882
# Method used to login a specific user
5983
def login_user(user, password = 'password')
6084
@current_admin_user = user

0 commit comments

Comments
 (0)