require 'rails_helper'
RSpec.describe 'account/articles/new', type: :view do
it 'renders new article form' do
stub_article { Article.new }
render
expect(rendered).to match(%r{form.+id="new_article".+action=\"#{account_articles_path}".+accept-charset=\"UTF-8\".+method=\"post\"})
end
def stub_article(&block)
controller.singleton_class.class_exec(block) do
helper_method :article
define_method :article do
block.call
end
end
end
end
require 'rails_helper'
RSpec.describe 'account/articles/new', type: :view do
it 'renders new article form' do
def view.article
Article.new
end
render
expect(rendered).to match %r{form.+id="new_article".+action=\"#{account_articles_path}".+accept-charset=\"UTF-8\".+method=\"post\"}
end
end
class MyClass
attr_accessor :name, :surname, :email
end
obj = MyClass.new
hash = {name: 'Ivan', surname: 'Ivanov', email: 'ivan@ivanov.com'}
hash.each do |key, value|
obj.public_send(%Q{#{key}=}, value) if obj.respond_to?(%Q{#{key}=})
end
p obj # => #<MyClass:0x007f9a4c11c478 @name="Ivan", @surname="Ivanov", @email="ivan@ivanov.com">
def callback_profile
render json: { text: 'Запрос успешно прошел.'}
end
$ ->
$("#callback_profile").on("ajax:success", (e, data, status, xhr) ->
$("#btn_submit").replaceWith data['text']
).on "ajax:error", (xhr, status, error) ->
$("#btn_submit").replaceWith 'Error!'
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
$name = $_POST['texts'];
echo $name;
}
else {
//index code
}
if(isset($_GET['context']))
{
if($_GET['context'] == 'ajax')
/*....*/
}
/<div\s+class="first"\s*>.*<\s*\/div>\s*<div\s+class="second"\s*>.*<\s*\/div>/
>> regex = /<div\s+class="first"\s*>.*<\s*\/div>\s*<div\s+class="second"\s*>.*<\s*\/div>/
>> s = %{<div class="first">First</div><div class="second">Second</div>}
>> regex =~ s
=> 0
т.е. вхождение с 0 символа
>> s = %{<div class="second">Second</div>}
=> "<div class=\"second\">Second</div>"
>> regex =~ s
=> nil
т.е. вхождения нет
>> s = %{<div class="first">First</div>}
=> "<div class=\"first\">First</div>"
>> regex =~ s
=> nil
т.е. вхождения нет