diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 3d20505eb..d54c2c5c5 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -40,7 +40,6 @@ def last_seven_profiles .is_published .by_region(current_region) .main_topic_translated_in(I18n.locale) - .order(created_at: :desc) .last 7 end end diff --git a/spec/requests/pages_controller_spec.rb b/spec/requests/pages_controller_spec.rb new file mode 100644 index 000000000..582fca30e --- /dev/null +++ b/spec/requests/pages_controller_spec.rb @@ -0,0 +1,21 @@ +describe 'PagesController', type: :request do + let!(:old_profile) { create(:published_profile, main_topic_en: 'history') } + let!(:profile_unpublished) { create(:unpublished_profile) } + let(:admin) { create(:profile, :admin) } + let!(:category) { create(:cat_science) } + + describe 'GET /' do + it 'returns http success' do + get '/' + expect(response).to have_http_status(:success) + end + + it 'shows the last 7 published profiles and excludes older and unpublished profiles' do + create_list(:published_profile, 7, main_topic_en: 'Mathematik Genie') + get '/' + expect(assigns(:newest_profiles).size).to eq(7) + expect(assigns(:newest_profiles)).not_to include(old_profile) + expect(assigns(:newest_profiles)).not_to include(profile_unpublished) + end + end +end