features/model.feature in katapult-0.4.1 vs features/model.feature in katapult-0.5.0
- old
+ new
@@ -186,88 +186,104 @@
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
+ person.attr :mood, assignable_values: %w[happy pensive]
person.attr :hobby, assignable_values: %w[soccer baseball], default: 'soccer', allow_blank: true
end
"""
And I successfully transform the application model including migrations
- Then the file "app/models/person.rb" should contain exactly:
+ Then the file "app/models/person.rb" should contain:
"""
- class Person < ApplicationRecord
-
-
assignable_values_for :age, {} do
9..99
end
+ assignable_values_for :mood, {} do
+ ["happy", "pensive"]
+ 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:
+ And the file "spec/models/person_spec.rb" should contain:
"""
- describe Person do
-
- describe '#to_s' do
- it 'returns the #age attribute' do
- subject.age = 9
- expect(subject.to_s).to eq("9")
- end
- end
-
describe '#age' do
it { is_expected.to allow_value(99).for(:age) }
it { is_expected.to_not allow_value(100).for(:age) }
end
+ describe '#mood' do
+ it { is_expected.to allow_value("pensive").for(:mood) }
+ it { is_expected.to_not allow_value("pensive-unassignable").for(:mood) }
+ end
+
describe '#hobby' do
it { is_expected.to allow_value("baseball").for(:hobby) }
it { is_expected.to_not allow_value("baseball-unassignable").for(:hobby) }
it 'has a default' do
expect(subject.hobby).to eq("soccer")
end
end
+ """
+ And the file "spec/factories/factories.rb" should contain:
+ """
+ factory :person do
+ age 9
+ mood "happy"
+ end
+ """
- end
-
+ When I write to "spec/models/factory_spec.rb" with:
"""
+ describe Person do
- When I run rspec
+ describe 'person factory' do
+ subject { create :person }
+
+ it 'generates a valid record' do
+ expect(subject).to be_valid
+ end
+ end
+
+ end
+ """
+ And I run rspec
Then the specs should pass
Scenario: Transform the application model multiple times
- Do not add routes twice.
+ Some generators inject code snippets into files. They should not do this
+ if their snippet is already present.
When I write to "lib/katapult/application_model.rb" with:
"""
- model('Car') { |c| c.attr :model }
- web_ui 'Car', &:crud
+ crud('Car') { |c| c.attr :model }
"""
And I successfully transform the application model
Then the file named "config/routes.rb" should contain:
"""
Rails.application.routes.draw do
root 'cars#index'
resources :cars
"""
- And I successfully transform the application model
+
+ When I successfully transform the application model
Then the file named "config/routes.rb" should contain:
"""
Rails.application.routes.draw do
root 'cars#index'
resources :cars
"""
And the file named "config/routes.rb" should contain "root 'cars#index'" exactly once
And the file named "config/routes.rb" should contain "resources :cars" exactly once
And the output should contain "Routes for :cars already exist! Not updated."
+
+ And the file named "spec/factories/factories.rb" should contain "factory :car" exactly once