<commit_before>routes = require '../routes'
_ = require 'underscore'
Backbone = require 'backbone'
sinon = require 'sinon'
fixtures = require '../../../../test/helpers/fixtures'
User = require '../../../models/user'

describe 'routes', ->

  beforeEach ->
    sinon.stub Backbone, 'sync'
    @req = { query: {}, user: new User(fixtures().users), params: {} }
    @res = { render: sinon.stub(), locals: fixtures().locals }

  afterEach ->
    Backbone.sync.restore()

  describe '#save', ->

    it 'saves the serialized form data to the vertical', ->
      @req.body =
        title: 'Foobar'
        featured_links: [{ title: 'foo' }, { title: 'bar' }, null, '']
      routes.save @req, @res
      Backbone.sync.args[0][1].toJSON().title.should.equal 'Foobar'
      Backbone.sync.args[0][1].toJSON().featured_links.length
        .should.equal 2
      Backbone.sync.args[0][1].toJSON().featured_links[0].title.should.equal 'foo'

  describe '#edit', ->

    it 'renders the edit page', ->
      routes.edit @req, @res
      Backbone.sync.args[0][2].success fixtures().verticals
      @res.render.args[0][0].should.equal 'edit'
      @res.render.args[0][1].vertical.get('id')
        .should.equal '55356a9deca560a0137aa4b7'<commit_msg>Adds test<commit_after>routes = require '../routes'
_ = require 'underscore'
Backbone = require 'backbone'
sinon = require 'sinon'
fixtures = require '../../../../test/helpers/fixtures'
User = require '../../../models/user'

describe 'routes', ->

  beforeEach ->
    sinon.stub Backbone, 'sync'
    @req = { query: {}, user: new User(fixtures().users), params: {} }
    @res = { render: sinon.stub(), locals: fixtures().locals }

  afterEach ->
    Backbone.sync.restore()

  describe '#save', ->

    it 'saves the serialized form data to the vertical', ->
      @req.body =
        title: 'Foobar'
        featured_links: [{ title: 'foo' }, { title: 'bar' }, null, '']
      routes.save @req, @res
      Backbone.sync.args[0][1].toJSON().title.should.equal 'Foobar'
      Backbone.sync.args[0][1].toJSON().featured_links.length
        .should.equal 2
      Backbone.sync.args[0][1].toJSON().featured_links[0].title.should.equal 'foo'

    it 'does not save featured links which are empty', ->
      @req.body =
        title: 'Foobar'
        featured_links: [{ title: '' }, { title: 'bar' }, null, '']
      routes.save @req, @res
      Backbone.sync.args[0][1].toJSON().featured_links.length
        .should.equal 1
      Backbone.sync.args[0][1].toJSON().featured_links[0].title.should.equal 'bar'

  describe '#edit', ->

    it 'renders the edit page', ->
      routes.edit @req, @res
      Backbone.sync.args[0][2].success fixtures().verticals
      @res.render.args[0][0].should.equal 'edit'
      @res.render.args[0][1].vertical.get('id')
        .should.equal '55356a9deca560a0137aa4b7'
{'fraction_non_alphanumeric': 0.18589065255731924, 'fraction_numerical': 0.022574955908289243, 'mean_word_length': 2.8902606310013716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7544619', 'n_tokens_mistral': 986, 'n_tokens_neox': 961, 'n_words': 191}