Skip to content

Commit 80dfcda

Browse files
camillevillatjgrathwell
authored andcommitted
Update association tests in types_of_tests.step
1 parent 1f1232f commit 80dfcda

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

sites/en/testing/types_of_tests.step

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,14 @@ message <<-MARKDOWN
33

44
In your Rails app, you have models, views, and controllers -> is MVC ringing a bell? :) Well, it should be no surprise that tests can be written for models, views, and controllers.
55

6-
Below, you will create the Orange model in your app so that the model file looks something like this:
7-
8-
<div class="console"><pre>
9-
class Orange < ActiveRecord::Base
10-
belongs_to :tree
11-
end
12-
</pre>
13-
</div>
14-
156
As you learned in the previous section, tests are used to verify that your code is working as expected. So, a couple things we can test right off the bat are that a tree should have certain associations and validations. Let's start by writing some model tests also known as unit tests! This link might come in handy to remember singular vs. plural Rails conventions: https://alexander-clark.com/blog/rails-conventions-singular-or-plural/
167
MARKDOWN
178

189
steps do
1910
step do
2011
message "First, create a orange model. By creating the model, a spec file will also be added to the models folder of the spec folder. Type this in the terminal:"
2112

22-
console_without_message "rails g model Orange"
13+
console_without_message "rails generate model Orange"
2314

2415
message "Then, run the migration to actually create the oranges table."
2516

@@ -30,7 +21,8 @@ steps do
3021

3122
console_without_message "bundle exec rspec"
3223

33-
message "You should see some report but no tests exist yet. So, let's add one! Copy the below test, paste it into the orange model spec file and then run 'bundle exec rspec' on the terminal again."
24+
message "You will see a report with one pending test. When you generated your Orange model, RSpec also generated a matching spec file. Copy the test below into spec/models/orange_spec.rb and run 'bundle exec rspec' on the terminal again."
25+
3426

3527
console_without_message <<-RUBY
3628
RSpec.describe Orange, :type => :model do
@@ -42,15 +34,24 @@ steps do
4234
end
4335
RUBY
4436

45-
message "Great, now you should see one passing test! That's an example of an association test. Let's modify that test to fail. Then, run 'bundle exec rspec' and see what happens. Cool! Let's revert back to the passing test. And, write a has many association test for the relationship between the Tree model (hint: this doesn't exist yet so you'll have to create the model and migrate!) and the Orange model!"
37+
message "Run 'bundle exec rspec'. This test fails! Let's add an associaton to our model. Add a belongs_to association to orange.rb:"
38+
39+
console_without_message <<-RUBY
40+
class Orange < ActiveRecord::Base
41+
belongs_to :tree
42+
end
43+
RUBY
4644

45+
message "Run 'bundle exec rspec' and now you should see one passing test! That's an example of an association test. Let's modify that test to fail. Then, run 'bundle exec rspec' and see what happens. Cool! Let's revert back to the passing test."
4746
end
48-
end
4947

48+
step do
5049

51-
message <<-MARKDOWN
52-
On to controller tests! Just like the Orange model, you will create the OrangesController, which will also create the spec files in the controller folder of the spec folder, in your app.
53-
MARKDOWN
50+
message "Now let's write a has_many association test for the relationship between the Tree model and the Orange model! (hint: this doesn't exist yet so you'll have to create the model and migrate!)"
51+
52+
message "On to controller tests! Just like the Orange model, you will create the OrangesController, which will also create spec files in the /spec/controllers folder of your app."
53+
end
54+
end
5455

5556
steps do
5657
step do

0 commit comments

Comments
 (0)