autoprefixer-rails (10.4.16.0)
execjs (~> 2)
aws-eventstream (1.3.0)
- aws-partitions (1.956.0)
- aws-sdk-core (3.201.1)
+ aws-partitions (1.957.0)
+ aws-sdk-core (3.201.2)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
progress (3.6.0)
psych (5.1.2)
stringio
- public_suffix (6.0.0)
+ public_suffix (6.0.1)
puma (5.6.8)
nio4r (~> 2.0)
quad_tile (1.0.1)
rubocop (~> 1.0)
ruby-openid (2.9.2)
ruby-progressbar (1.13.0)
- ruby-vips (2.2.1)
+ ruby-vips (2.2.2)
ffi (~> 1.12)
+ logger
rubyzip (2.3.2)
sanitize (6.1.1)
crass (~> 1.0.2)
sass-embedded (1.64.2)
google-protobuf (~> 3.23)
rake (>= 13.0.0)
- selenium-webdriver (4.22.0)
+ selenium-webdriver (4.23.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
thor (1.3.1)
tilt (2.4.0)
timeout (0.4.1)
- turbo-rails (2.0.5)
+ turbo-rails (2.0.6)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
can [:new, :show, :create, :destroy], :oauth2_authorization
can [:edit, :update, :destroy], :account
can [:show], :dashboard
- can [:new, :create, :edit, :update, :subscribe, :unsubscribe], DiaryEntry
+ can [:new, :create, :subscribe, :unsubscribe], DiaryEntry
+ can :update, DiaryEntry, :user => user
can [:create], DiaryComment
can [:make_friend, :remove_friend], Friendship
can [:new, :create, :reply, :show, :inbox, :outbox, :muted, :mark, :unmute, :destroy], Message
@title = t "diary_entries.edit.title"
@diary_entry = DiaryEntry.find(params[:id])
- if current_user != @diary_entry.user ||
+ if cannot?(:update, @diary_entry) ||
(params[:diary_entry] && @diary_entry.update(entry_params))
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
else
</li>
<% end %>
- <% if current_user && current_user == diary_entry.user %>
+ <% if can?(:edit, diary_entry) %>
<li><%= link_to t(".edit_link"), edit_diary_entry_path(diary_entry.user, diary_entry) %></li>
<% end %>
<%= f.form_group do %>
<%= label_tag "user_block_period", t(".period"), :class => "form-label" %>
<%= select_tag("user_block_period",
- options_for_select(UserBlock::PERIODS.collect { |h| [block_duration_in_words(h.hours), h.to_s] }, params[:user_block_period]),
+ options_for_select(UserBlock::PERIODS.collect { |h| [block_duration_in_words(h.hours), h.to_s] },
+ UserBlock::PERIODS.min_by { |h| (params[:user_block_period].to_i - h).abs }),
:class => "form-select") %>
<% end %>
assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
end
+ def test_update
+ user = create(:user)
+ other_user = create(:user)
+ diary_entry = create(:diary_entry, :language_code => "en", :user => user, :title => "Original Title")
+
+ put diary_entry_path(user, diary_entry, :diary_entry => { :title => "Updated Title" })
+ assert_response :forbidden
+ diary_entry.reload
+ assert_equal "Original Title", diary_entry.title
+
+ session_for(other_user)
+ put diary_entry_path(user, diary_entry, :diary_entry => { :title => "Updated Title" })
+ assert_redirected_to diary_entry_path(user, diary_entry)
+ diary_entry.reload
+ assert_equal "Original Title", diary_entry.title
+
+ session_for(user)
+ put diary_entry_path(user, diary_entry, :diary_entry => { :title => "Updated Title" })
+ assert_redirected_to diary_entry_path(user, diary_entry)
+ diary_entry.reload
+ assert_equal "Updated Title", diary_entry.title
+ end
+
def test_index_all
diary_entry = create(:diary_entry)
geo_entry = create(:diary_entry, :latitude => 51.50763, :longitude => -0.10781)
assert_select "p", "Sorry, the user block with ID 99999 could not be found."
end
+ ##
+ # test the edit action when the remaining block duration doesn't match the available select options
+ def test_edit_duration
+ moderator_user = create(:moderator_user)
+
+ freeze_time do
+ active_block = create(:user_block, :creator => moderator_user, :ends_at => Time.now.utc + 96.hours)
+
+ session_for(moderator_user)
+ get edit_user_block_path(active_block)
+
+ assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
+ assert_select "select#user_block_period", :count => 1 do
+ assert_select "option[value='96'][selected]", :count => 1
+ end
+ end
+
+ travel 2.hours
+ get edit_user_block_path(active_block)
+
+ assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
+ assert_select "select#user_block_period", :count => 1 do
+ assert_select "option[value='96'][selected]", :count => 1
+ end
+ end
+ end
+ end
+
##
# test the create action
def test_create