• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

boston-library / ark-manager / 580

10 Oct 2025 06:36PM UTC coverage: 74.227%. Remained the same
580

Pull #128

travis-pro

web-flow
Merge ecab22e68 into de47816d5
Pull Request #128: Bump rack from 3.1.17 to 3.1.18

360 of 485 relevant lines covered (74.23%)

22.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.38
/app/controllers/arks_controller.rb
1
# frozen_string_literal: true
2

3
class ArksController < ApplicationController
1✔
4
  before_action :find_ark, except: [:create]
1✔
5
  before_action :check_for_existing_ark, only: [:create]
1✔
6

7
  def show
1✔
8
    redirect_to @ark.redirect_url and return if redirect_for_object?
9✔
9

10
    # Renders JSON if !redirect_for_object
11
    fresh_when last_modified: @ark.updated_at.utc, strong_etag: @ark
7✔
12
  end
13

14
  def create
1✔
15
    if @ark
20✔
16
      Rails.logger.debug 'Found a matching ark!'
10✔
17
      Rails.logger.debug @ark.to_s
10✔
18

19
      render action: :show, status: :ok and return if !@ark.deleted?
10✔
20

21
      Rails.logger.debug "Ark #{@ark.noid} was deleted...Restoring..."
5✔
22

23
      status = :accepted
5✔
24
      @ark.deleted = false
5✔
25
    else
26
      status = :created
10✔
27
      @ark = Ark.new(ark_params)
10✔
28

29
      Rails.logger.debug 'Initialized new Ark!'
10✔
30
      Rails.logger.debug @ark.to_s
10✔
31
    end
32

33
    render status: status and return if @ark.save
15✔
34

35
    Rails.logger.error 'Ark failed to save!'
5✔
36
    Rails.logger.error @ark.errors.full_messages.join("\n")
5✔
37

38
    @errors = build_ark_errors(@ark.errors.messages)
5✔
39
    render status: :unprocessable_entity
5✔
40
  end
41

42
  def destroy
1✔
43
    @ark.deleted = true
6✔
44
    head :no_content and return if @ark.save
6✔
45

46
    errors = build_ark_errors(@ark.errors.messages)
×
47
    render json: { errors: errors }, status: :unprocessable_entity
×
48
  end
49

50
  def iiif_manifest
1✔
51
    redirect_to "#{@ark.redirect_url}/manifest"
2✔
52
  end
53

54
  def iiif_canvas
1✔
55
    @canvas_object = Ark.select(:created_at, :namespace_ark, :noid, :pid, :url_base, :deleted).object_in_view(params[:namespace], params[:canvas_object_id]).first!
3✔
56

57
    redirect_to "#{@ark.redirect_url}/canvas/#{@canvas_object.pid}"
2✔
58
  end
59

60
  def iiif_annotation
1✔
61
    @annotation_object = Ark.select(:created_at, :namespace_ark, :noid, :pid, :url_base, :deleted).object_in_view(params[:namespace], params[:annotation_object_id]).first!
3✔
62

63
    redirect_to "#{@ark.redirect_url}/annotation/#{@annotation_object.pid}"
2✔
64
  end
65

66
  def iiif_collection
1✔
67
    redirect_to "#{@ark.redirect_url}/iiif_collection"
2✔
68
  end
69

70
  def iiif_search
1✔
71
    iiif_query_params = iiif_search_params.to_query
4✔
72

73
    search_redirect_url = iiif_query_params.blank? ? "#{@ark.redirect_url}/iiif_search" : "#{@ark.redirect_url}/iiif_search?#{iiif_query_params}"
4✔
74

75
    redirect_to search_redirect_url
4✔
76
  end
77

78
  private
1✔
79

80
  def find_ark
1✔
81
    if params[:object_in_view]
49✔
82
      @ark = Ark.select(:created_at, :namespace_ark, :noid, :pid, :url_base, :deleted).object_in_view(params[:namespace], params[:noid]).first!
28✔
83
    else
84
      @ark = Ark.active.find(params[:id])
21✔
85
    end
86
  end
87

88
  def check_for_existing_ark
1✔
89
    Rails.logger.debug 'Checking for existing Ark...'
20✔
90
    Rails.logger.debug "==== :ark_params are #{ark_params.inspect} ===="
20✔
91

92
    @ark = if ark_params[:parent_pid]
20✔
93
             Ark.with_parent_and_local_id_and_model_type(ark_params[:parent_pid], ark_params[:local_original_identifier], ark_params[:local_original_identifier_type], ark_params[:model_type]).first
17✔
94
           else
95
             Ark.without_parent_and_with_local_id_and_model_type(ark_params[:local_original_identifier], ark_params[:local_original_identifier_type], ark_params[:model_type]).first
3✔
96
           end
97
  end
98

99
  def redirect_for_object?
1✔
100
    params[:object_in_view] || !request.format.json?
9✔
101
  end
102

103
  def iiif_search_params
1✔
104
    params.permit(:q, :motivation, :date, :user)
4✔
105
  end
106

107
  def ark_params
1✔
108
    params.require(:ark).permit(:local_original_identifier,
127✔
109
                                :local_original_identifier_type,
110
                                :namespace_ark,
111
                                :namespace_id,
112
                                :url_base,
113
                                :model_type,
114
                                :parent_pid,
115
                                secondary_parent_pids: [])
116
  end
117

118
  def build_ark_errors(ark_errors = {})
1✔
119
    return default_ark_error if ark_errors.blank?
5✔
120

121
    ark_errors.reduce([]) do |r, (attr, msg)|
5✔
122
      r << {
31✔
123
        title: 'Unprocessable Entity',
124
              status: 422,
125
              detail: msg.join(','),
126
              source: { pointer: "/data/attributes/#{attr}" }
127
      }
128
    end
129
  end
130

131
  def default_ark_error
1✔
132
    [{
133
      title: 'Unprocessable Entity',
×
134
      status: 422,
135
      detail: 'Unknown Errors caused Ark to fail saving! Check the logs!',
136
      source: { pointer: '/data/attributes/:unknown' }
137
    }]
138
  end
139
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc