Skip to content

Commit ac1f139

Browse files
authored
Merge pull request #3517 from AlchemyCMS/only-draft-element-assignments
fix(assignments): Only list draft elements
2 parents b1c49f5 + fc0fe77 commit ac1f139

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

app/controllers/alchemy/admin/attachments_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def index
3737

3838
# The resources controller renders the edit form as default for show actions.
3939
def show
40-
@assignments = @attachment.related_ingredients.joins(element: :page)
40+
@assignments = @attachment.related_ingredients.joins(element: :page).merge(PageVersion.drafts)
4141
render :show
4242
end
4343

app/controllers/alchemy/admin/pictures_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def show
4343
@previous = @pictures.prev_page
4444
@next = @pictures.next_page
4545

46-
@assignments = @picture.related_ingredients.joins(element: :page)
46+
@assignments = @picture.related_ingredients.joins(element: :page).merge(PageVersion.drafts)
4747
@picture_description = @picture.descriptions.find_or_initialize_by(
4848
language_id: Alchemy::Current.language.id
4949
)

spec/controllers/alchemy/admin/attachments_controller_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ module Alchemy
9595
get :show, params: {id: attachment.id}
9696
expect(response).to render_template(:show)
9797
end
98+
99+
context "with assignments" do
100+
let!(:page) { create(:alchemy_page) }
101+
let!(:element) { create(:alchemy_element, page: page) }
102+
let!(:ingredient) { create(:alchemy_ingredient_file, element: element, related_object: attachment) }
103+
104+
before do
105+
page.publish!
106+
end
107+
108+
it "assigns all file ingredients having an assignment to @assignments" do
109+
get :show, params: {id: attachment.id}
110+
expect(assigns(:assignments)).to eq([ingredient])
111+
end
112+
end
98113
end
99114

100115
describe "#create" do

spec/controllers/alchemy/admin/pictures_controller_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ module Alchemy
179179
let!(:element) { create(:alchemy_element, page: page) }
180180
let!(:ingredient) { create(:alchemy_ingredient_picture, element: element, related_object: picture) }
181181

182+
before do
183+
page.publish!
184+
end
185+
182186
it "assigns all picture ingredients having an assignment to @assignments" do
183187
get :show, params: {id: picture.id}
184188
expect(assigns(:assignments)).to eq([ingredient])

0 commit comments

Comments
 (0)