mercredi 18 novembre 2015

Converting a Ruby application to Ruby on Rails ActiveRecord one

Let's say we have a ruby class like this:

class Song
  attr_reader :id, :title, :author, :path

  def initialize(id, title, author, path)
    @id = id
    @title= title
    @author= author
    @path = path
  end

  def change_title(new)
    @title = new
  end

  def change_path(new)
    @path = new
  end

  # other functions here, some operations and stuff

end

If we were to "convert" it to an Rails ActiveRecord one, what should we do? (examples please) I am quite new to this and don't quite understand how it works, so figured I might ask here.

The second part of this is, we have lots of tests (RSpec for example)

before(:each){
  @song = Song.new(Random.rand(100), 
                   'Some song', 'Some author', 'C:/song.mp3')
}    

it 'change songs path' do
  new_path = 'D:/new_path/something.mp3'
  @song.change_path(new_path)
  expect(@song.path).to eq new_path
end

Could you provide me with some examples of how could we produce testing data for the tests and how should we change the tests, like using Fixtures or Factory_girl or etc.

Sorry for quite stupid questions for some of you maybe, because there is documentation, but I find it hard to understand, so thought maybe actual situation like I provided might help.

Aucun commentaire:

Enregistrer un commentaire