Sha256: 9e002749a5f99ccdd8d25d52761158ff7df519047458d2f8c69b6f85548181a8

Contents?: true

Size: 1.73 KB

Versions: 19

Compression:

Stored size: 1.73 KB

Contents

require 'test_helper'

class AsTest < BaseTest
  class AlbumForm < Reform::Form
    property :name, from: :title

    property :single, from: :hit do
      property :title
    end

    collection :tracks, from: :songs do
      property :name, from: :title
    end

    property :band do
      property :company, from: :label do
        property :business, from: :name
      end
    end
  end

  let (:song2) { Song.new("Roxanne") }

  let (:params) {
      {
        "name" => "Best Of The Police",
        "single"   => {"title" => "So Lonely"},
        "tracks" => [{"name" => "Message In A Bottle"}, {"name" => "Roxanne"}]
      }
    }

  subject { AlbumForm.new(Album.new("Best Of", hit, [Song.new("Fallout"), song2])) }

  it { subject.name.must_equal "Best Of" }
  it { subject.single.title.must_equal "Roxanne" }
  it { subject.tracks[0].name.must_equal "Fallout" }
  it { subject.tracks[1].name.must_equal "Roxanne" }


  describe "#validate" do


    before { subject.validate(params) }

    it { subject.name.must_equal "Best Of The Police" }
    it { subject.single.title.must_equal "So Lonely" }
    it { subject.tracks[0].name.must_equal "Message In A Bottle" }
    it { subject.tracks[1].name.must_equal "Roxanne" }
  end


  describe "#sync" do
    before {
      subject.tracks[1].name = "Livin' Ain't No Crime"
      subject.sync
    }

    it { song2.title.must_equal "Livin' Ain't No Crime" }
  end


  describe "#save (nested hash)" do
    before { subject.validate(params) }

    it do
      hash = nil

      subject.save do |nested_hash|
        hash = nested_hash
      end

      hash.must_equal({"title"=>"Best Of The Police", "hit"=>{"title"=>"So Lonely"}, "songs"=>[{"title"=>"Message In A Bottle"}, {"title"=>"Roxanne"}]})
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
reform-2.2.4 test/from_test.rb
reform-2.2.3 test/from_test.rb
reform-2.2.2 test/from_test.rb
reform-2.2.1 test/from_test.rb
reform-2.2.0 test/from_test.rb
reform-2.2.0.rc1 test/from_test.rb
reform-2.1.0 test/from_test.rb
reform-2.1.0.rc1 test/from_test.rb
reform-2.0.5 test/from_test.rb
reform-2.0.4 test/from_test.rb
reform-2.0.3 test/from_test.rb
reform-2.0.2 test/from_test.rb
reform-2.0.1 test/from_test.rb
reform-2.0.0 test/from_test.rb
reform-2.0.0.rc3 test/from_test.rb
reform-2.0.0.rc2 test/from_test.rb
reform-2.0.0.rc1 test/from_test.rb
reform-2.0.0.beta2 test/from_test.rb
reform-2.0.0.beta1 test/from_test.rb