public function test_restoreTopicToSection_restores_a_topic_and_views()
 {
     // GIVEN I have a topic with posts in a section
     $section = factory(Section::class, 1)->create();
     $topic = factory(Topic::class, 1)->create(['section_id' => $section->id]);
     factory(Post::class, 20)->create(['topic_id' => $topic->id]);
     $topic_id = $topic->id;
     // and a user reads that topic
     $user = factory(User::class, 1)->create();
     \Nexus\Helpers\ViewHelper::updateReadProgress($user, $topic);
     $viewsCount = $topic->views->count();
     $this->assertNotEquals($viewsCount, 0);
     // and then that topic is deleted
     $topic->delete();
     // check topic deleted
     $this->assertTrue($topic->trashed());
     // and that we have no views - need to use trashed here
     $this->assertEquals(Topic::withTrashed()->find($topic_id)->views->count(), 0);
     // WHEN the topic is restored to the section
     \Nexus\Helpers\RestoreHelper::restoreTopicToSection($topic, $section);
     // check posts and views are restored
     $this->assertEquals($topic->views->count(), $viewsCount);
     // THEN the topic is restored
     $this->assertFalse($topic->trashed());
 }
 public function topic(Requests\topic\RestoreRequest $request, $id)
 {
     $trashedTopic = \Nexus\Topic::onlyTrashed()->findOrFail($id);
     $destinationSection = \Nexus\Section::findOrFail($request->destination);
     \Nexus\Helpers\RestoreHelper::restoreTopicToSection($trashedTopic, $destinationSection);
     $redirect = action('Nexus\\SectionController@show', ['id' => $destinationSection->id]);
     return redirect($redirect);
 }