features/model.feature in katapult-0.3.0 vs features/model.feature in katapult-0.4.0
- old
+ new
@@ -1,6 +1,7 @@
#@announce-output
+#@announce-stderr
Feature: Generate Models
Background:
Given a new Rails application with Katapult basics installed
@@ -11,15 +12,17 @@
model 'Car'
"""
And I successfully transform the application model
Then the file "app/models/car.rb" should contain exactly:
"""
- class Car < ActiveRecord::Base
+ class Car < ApplicationRecord
+
def to_s
"Car##{id}"
end
+
end
"""
And there should be a migration with:
"""
@@ -45,10 +48,14 @@
end
end
"""
+ And the file "spec/factories/factories.rb" should contain:
+ """
+ factory :car
+ """
Scenario: Generate ActiveRecord Model with attributes
When I write to "lib/katapult/application_model.rb" with:
"""
@@ -70,17 +77,20 @@
end
"""
And I successfully transform the application model including migrations
Then the file "app/models/person.rb" should contain exactly:
"""
- class Person < ActiveRecord::Base
+ class Person < ApplicationRecord
+
include DoesFlag[:locked, default: false]
+
has_defaults({:homepage=>"http://www.makandra.de"})
def to_s
age.to_s
end
+
end
"""
And there should be a migration with:
"""
@@ -146,10 +156,35 @@
"""
And I transform the application model
Then the output should contain "Katapult::Attribute does not support option :invalid_option. (Katapult::Element::UnknownOptionError)"
+ Scenario: Specify model associations
+ When I write to "lib/katapult/application_model.rb" with:
+ """
+ model('Company') { |c| c.attr :name }
+ model 'User' do |user|
+ user.belongs_to 'Company'
+ end
+ """
+ And I successfully transform the application model including migrations
+ Then the file "app/models/company.rb" should contain "has_many :users"
+ And the file "app/models/user.rb" should contain "belongs_to :company"
+ And the file "app/models/user.rb" should contain:
+ """
+ assignable_values_for :company, {:allow_blank=>true} do
+ Company.all.to_a
+ end
+ """
+
+ And there should be a migration with:
+ """
+ create_table :users do |t|
+ t.integer :company_id
+ """
+
+
Scenario: Specify assignable values
When I write to "lib/katapult/application_model.rb" with:
"""
model 'Person' do |person|
person.attr :age, type: :integer, assignable_values: 9..99
@@ -157,20 +192,24 @@
end
"""
And I successfully transform the application model including migrations
Then the file "app/models/person.rb" should contain exactly:
"""
- class Person < ActiveRecord::Base
+ class Person < ApplicationRecord
+
+
assignable_values_for :age, {} do
9..99
end
+
assignable_values_for :hobby, {:allow_blank=>true, :default=>"soccer"} do
["soccer", "baseball"]
end
def to_s
age.to_s
end
+
end
"""
And the file "spec/models/person_spec.rb" should contain exactly:
"""