Class: SpecViews::ViewsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/spec_views/views_controller.rb

Instance Method Summary collapse

Instance Method Details

#acceptObject



73
74
75
76
# File 'app/controllers/spec_views/views_controller.rb', line 73

def accept
  accept_directory(directory)
  redirect_to action: :index, challenger: :next
end

#accept_allObject



78
79
80
81
82
83
# File 'app/controllers/spec_views/views_controller.rb', line 78

def accept_all
  directories.each do |dir|
    accept_directory(dir) if dir.challenger?
  end
  redirect_to action: :index
end

#batchObject



23
24
25
26
# File 'app/controllers/spec_views/views_controller.rb', line 23

def batch
  @change = BatchDiff.new(directories).biggest_change
  redirect_to(url_for(action: :index), notice: 'No identical changes found') unless @change
end

#batch_acceptObject



28
29
30
31
32
33
34
35
36
# File 'app/controllers/spec_views/views_controller.rb', line 28

def batch_accept
  batch_diff = BatchDiff.new(directories)
  batch_diff.accept_by_hash!(params[:hash])
  if batch_diff.changes.size > 1
    redirect_to(action: :batch)
  else
    redirect_to(action: :index)
  end
end

#compareObject



52
53
54
# File 'app/controllers/spec_views/views_controller.rb', line 52

def compare
  @directory = directory
end

#destroy_outdatedObject



97
98
99
100
101
102
103
104
# File 'app/controllers/spec_views/views_controller.rb', line 97

def destroy_outdated
  @directories = directories
  @latest_run = directories.map(&:last_run).max
  @directories.each do |dir|
    dir.delete! if dir.last_run < @latest_run
  end
  redirect_to action: :index
end

#diffObject



56
57
58
59
60
61
62
63
64
# File 'app/controllers/spec_views/views_controller.rb', line 56

def diff
  if directory.content_type.pdf?
    redirect_to action: :compare
    return
  end
  @champion = get_view(directory.champion_path, html_safe: false)
  @challenger = get_view(directory.challenger_path, html_safe: false)
  @directory = directory
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/spec_views/views_controller.rb', line 10

def index
  @directories = directories
  @latest_run = directories.map(&:last_run).max
  return unless params[:challenger] == 'next'

  first = @directories.detect(&:challenger?)
  if first
    redirect_to(action: :compare, id: first)
  else
    redirect_to(action: :index, challenger: nil)
  end
end

#previewObject



66
67
68
69
70
71
# File 'app/controllers/spec_views/views_controller.rb', line 66

def preview
  @directory = directory
  @next = directories[directories.index(@directory) + 1]
  index = directories.index(@directory)
  @previous = directories[index - 1] if index.positive?
end

#rejectObject



92
93
94
95
# File 'app/controllers/spec_views/views_controller.rb', line 92

def reject
  directory.remove_challenger
  redirect_to action: :index, challenger: :next
end

#reject_allObject



85
86
87
88
89
90
# File 'app/controllers/spec_views/views_controller.rb', line 85

def reject_all
  directories.each do |dir|
    dir.remove_challenger if dir.challenger?
  end
  redirect_to action: :index
end

#showObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/spec_views/views_controller.rb', line 38

def show
  path = directory.champion_path
  path = directory.challenger_path if params[:view] == 'challenger'
  if directory.content_type.pdf?
    send_data(
      get_view(path),
      filename: 'a.pdf',
      type: 'application/pdf', disposition: 'inline'
    )
  else
    render html: get_view(path)
  end
end