require 'spec_helper' module Localtower module Generators describe Relation do before(:each) do end after(:all) do end it 'create a relation' do ::Localtower::Generators::Model.new(attributes_for(:post_one)).run ::Localtower::Generators::Model.new(attributes_for(:user_one)).run ::Localtower::Generators::Relation.new(attributes_for(:relation_one)).run expect(File.exist?("#{Rails.root}/app/models/user_post.rb")).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user_post.rb", /class UserPost/)).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /create_table "user_posts"/)).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /t.integer "user_id"/)).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /t.integer "post_id"/)).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user.rb", /has_many :posts, through: :user_posts/)).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user.rb", /has_many :posts/)).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/post.rb", /has_many :users/)).to eq(true) expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/post.rb", /has_many :users, through: :user_posts/)).to eq(true) end end end end