Add missing feature and model specs on proposal and debates.

This commit is contained in:
taitus
2017-08-01 18:00:02 +02:00
parent 11395e0b27
commit 33e13dbfd0
6 changed files with 246 additions and 101 deletions

View File

@@ -351,6 +351,45 @@ feature 'Debates' do
expect(current_url).to include('order=created_at')
expect(current_url).to include('page=1')
end
context 'Recommendations' do
background do
Setting['feature.user.recommendations'] = true
create(:debate, title: 'Best', cached_votes_total: 10)
create(:debate, title: 'Medium', cached_votes_total: 5)
create(:debate, title: 'Worst', cached_votes_total: 1)
end
after do
Setting['feature.user.recommendations'] = nil
end
scenario 'Debates can not ordered by recommendations when there is not an user logged', :js do
visit debates_path
expect(page).not_to have_selector('a', text: 'recommendations')
end
scenario 'Debates are ordered by recommendations when there is an user logged', :js do
user = create(:user)
login_as(user)
visit debates_path
click_link 'recommendations'
expect(page).to have_selector('a.active', text: 'recommendations')
within '#debates' do
expect('Best').to appear_before('Medium')
expect('Medium').to appear_before('Worst')
end
expect(current_url).to include('order=recommendations')
expect(current_url).to include('page=1')
end
end
end
context "Search" do
@@ -759,6 +798,32 @@ feature 'Debates' do
end
end
scenario "Reorder by recommendations results maintaing search", :js do
Setting['feature.user.recommendations'] = true
user = create(:user)
login_as(user)
debate1 = create(:debate, title: "Show you got", cached_votes_total: 10, tag_list: "Sport")
debate2 = create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport")
debate3 = create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport")
debate4 = create(:debate, title: "Do not display", cached_votes_total: 1)
proposal1 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal1, user: user)
visit debates_path
fill_in "search", with: "Show you got"
click_button "Search"
click_link 'recommendations'
expect(page).to have_selector("a.active", text: "recommendations")
within("#debates") do
expect(all(".debate")[0].text).to match "Show you got"
expect(all(".debate")[1].text).to match "Show what you got"
expect(page).to_not have_content "Do not display with same tag"
expect(page).to_not have_content "Do not display"
end
Setting['feature.user.recommendations'] = nil
end
scenario 'After a search do not show featured debates' do
featured_debates = create_featured_debates
debate = create(:debate, title: "Abcdefghi")