```ruby
require 'spec_helper'

describe MessagesController do
  let(:user) { create(:user) }
  let(:exercise) { create(:exercise) }

  before do
    assignment = exercise.submit_solution! user, content: ''
    10.times do
      assignment.send_message! content: 'a',
                               type: 'success',
                               date: '1/1/1',
                               sender: 'aguspina87@gmail.com'
    end
  end

  context 'when  not authenticated' do
    before { get :index }

    it { expect(response.status).to eq 403 }
  end

  context 'when authenticated' do
    before { set_current_user! user }
    before { get :index }

    it { expect(response.status).to eq 200 }
    it { expect(response.body.parse_json).to json_like(has_messages: true, messages_count: 10) }
  end
end
```

Add messages controller spec for creating messages
user
```ruby
require 'spec_helper'

describe MessagesController do
  let(:user) { create(:user) }
  let(:exercise) { create(:exercise) }
  before { set_current_user! user }
  before { allow_any_instance_of(MessagesController).to receive(:message_params).and_return content: 'foo' }

  describe 'post when no previous assignment' do
    before { post :create, {exercise_id: exercise.id} }

    it { expect(response.status).to eq 302 }
    it { expect(user.assignments.size).to eq 1 }
    it { expect(user.messages.size).to eq 1 }
  end

  describe 'post when previous assignment' do
    let(:assignment) { exercise.submit_solution!(user, content: '') }
    before { post :create, {exercise_id: exercise.id} }

    it { expect(response.status).to eq 302 }
    it { expect(user.assignments.size).to eq 1 }
    it { expect(user.messages.size).to eq 1 }
  end
end
```
assistant